发布网友
共2个回答
热心网友
用JS改变图像的原始大小方法:
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
$('input[type=file]').change(function(){
var file=this.files[0];
var reader=new FileReader();
var image=new Image();
reader.readAsDataURL(file);
reader.onload=function(){
// 通过 reader.result 来访问生成的 DataURL
var url=reader.result;
image.src=url;
alert(image.width);
alert(image.height);
image.height /=4;
image.width /=4;
canvas.setAttribute("width", image.width+"px");
canvas.setAttribute("height", image.height+"px");
alert(image.naturalWidth);
alert(image.naturalHeight);
context.drawImage(image,0,0,image.width,image.height);
};
});
热心网友
看canvas的用法,context.drawImage(image,0,0,image.width,image.height)之后用canvas.toDataURL()把调整大小后的图片转换为url就可以了