简体   繁体   English

为下载客户端调整图像大小

[英]Resize image for download client side

Is there any way through any type of client side script to get an external image (ex: http://www.google.com/image.jpg ) and resize it when the user copies the image so that the pasted image will be resized?有没有办法通过任何类型的客户端脚本获取外部图像(例如: http://www.google.com/image.jpg )并在用户复制图像时调整其大小,以便调整粘贴图像的大小? And I can't get HTML5 canvas to work.而且我无法让 HTML5 canvas 工作。

I'm working out of Dreamweaver CS5.5 and creating an Air App.我正在使用 Dreamweaver CS5.5 并创建一个 Air App。 The code works in live view but not when I preview the Air App.该代码在实时视图中有效,但在我预览 Air App 时无效。 Here is the code that is not working:这是不起作用的代码:

function test(){

var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var img = new Image();
img.onload = function(){
context.drawImage(img, 0,0);
};


img.src="image.jpg";

 }

You can try drawing the image then doing img.src = canvas.toDataURL('image/png') prior to the user dragging.您可以尝试绘制图像,然后在用户拖动之前执行img.src = canvas.toDataURL('image/png') This will cause the canvas to output its data to the image tag.这将导致 canvas 到 output 其数据到图像标签。 The canvas should be invisible, while the image is the visible element the user should drag. canvas 应该是不可见的,而图像是用户应该拖动的可见元素。

To resize the image, specify the width and height in the drawImage .要调整图像大小,请在drawImage中指定宽度和高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM