2013-10-08 91 views
0

在我基礎煎茶應用程序,我想將圖像轉換爲base64,base64相互轉換前的圖像,在此之前,我要調整原有one.Here我都用爲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,/, ""); 
    } 
    } 
} 
代碼

如何調整或REDIMENSION轉換前的形象呢?我曾嘗試與改變img.style.width和hieght但在all.Please無變化幫我

+1

連打請檢查的drawImage額外的可選參數...你可以直接調整畫布上的圖像同時借鑑它。生成的dataURL將反映調整後的圖像。並記得減少canvas.width和canvas.height – devnull69

+0

@ devnull69任何例子? – ioseve

回答