2012-01-25 17 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 
    } 
}); 
関連する問題