2012-01-25 34 views
0

我有圖庫管理器和放置區(用於圖庫圖像)。 文件丟失時。我使用FileReader進行讀取並獲取圖像的base64數據。 我的目標是調整客戶端上的所有圖像(使拇指/正常圖像)。 問題:我可以將base64放入畫布中,然後調整畫布大小並獲取新的調整大小的圖像base64?在客戶端讀取文件圖像數據並調整其大小

回答

1
$.getImageData({ 
    url: "http://farm4.static.flickr.com/3002/2758349058_ab6dc9cfdc_z.jpg?zz=1", 
    success: function(image){ 

    // Set up the canvas 
    var can = document.getElementsByTagName('canvas')[0]; 
    var ctx = can.getContext('2d'); 

    // Set the canvas width and heigh to the same as the image 
    $(can).attr('width', image.width); 
    $(can).attr('height', image.height); 

    // Draw the image on to the canvas 
    ctx.drawImage(image, 0, 0, image.width, image.height); 

    // Get the image data 
    var image_data = ctx.getImageData(0, 0, image.width, image.height); 
    var image_data_array = image_data.data; 


    // Write the image data to the canvas 
    ctx.putImageData(image_data, 0, 0); 

    }, 
    error: function(xhr, text_status){ 
    // Handle your error here 
    } 
}); 
相關問題