微信公开课小程序热门讨论「如何用JS改变图像的原始大小」最新回复-看canvas的用法,context.drawImage(image,0,0,image.width,image.height)之后用canvas.toDataURL()把调整大小后的图片转换为url就可以了
用JS改变图像的原始大小方法:varcanvas=document.getElementById(canvas);varcontext=canvas.getContext(2d);$(input[type=file]).change(function(){varfile=this.files[0];varreader=newFileReader();varimage=newImage();reader.readAsDataURL(file);reader.onload=function(){//通过reader.result来访问生成的DataURLvarurl=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);};});本回答被提问者采纳 更多有关「如何用JS改变图像的原始大小」的疑问请扫码关注微信公开课+小程序!了解更多