Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在base64转换之前调整图像大小_Javascript_Extjs_Sencha Touch 2 - Fatal编程技术网

Javascript 如何在base64转换之前调整图像大小

Javascript 如何在base64转换之前调整图像大小,javascript,extjs,sencha-touch-2,Javascript,Extjs,Sencha Touch 2,在我基于sencha的应用程序中,我想将图像转换为base64,在此之前我想调整原始图像的大小 function getBase64FromImageUrl(URL) { var img = new Image(); img.style.width = '5%', img.style.height = '5%', img.src = URL; img.onload = function () { var canvas = document.createElement("canvas");

在我基于sencha的应用程序中,我想将图像转换为base64,在此之前我想调整原始图像的大小

function getBase64FromImageUrl(URL)
{
var img = new Image();
img.style.width = '5%',
img.style.height = '5%',
img.src = URL;
img.onload = function ()
{
    var canvas = document.createElement("canvas");
    canvas.width =this.width;
    canvas.height =this.height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(this, 10, 10);
    var dataURL = canvas.toDataURL("image/jpg");
    if(App.gvars.userpic=='1')
    {
    cdd=dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
    }
    if(App.gvars.userpic=='2')
    {
    c=dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
    }
   }
}

如何在转换前调整图像的大小或重新确定图像的尺寸?我已尝试更改img.style.width和hight,但没有任何更改。请帮助我

根据devnull69的建议,在将图像添加到画布时,只需使用drawImage()调整图像大小

请参阅或上的API


您甚至可以在

的实时编码示例中使用这些值。请检查drawImage的其他可选参数。。。绘制图像时,可以直接调整画布上图像的大小。生成的dataURL将反映调整大小的图像。记住减少canvas.width和canvas.heightaccordingly@devnull69有什么例子吗?