2017-05-31 74 views
0

JQuery的調整後的圖像畫布大小調整隻圖像沒有上述功能的調整大小圖像的畫布JQuery的調整後的圖像畫布大小調整隻圖像不是一個帆布

function resizeImage(width, height){ 
    var image = document.getElementById('resizeImage'), 
    canvas = document.createElement('canvas'), 
    ctx = canvas.getContext('2d'); 
    ctx.drawImage(image,cropLeft, cropTop, cropWidth, cropHeight,10,10,width,height); 

    return canvas; 
    }; 

但表現回報帆布額外帆布一部分;

我怎樣才能獲得固定高度的寬度調整大小圖像使用簡單的jQuery的HTML?

回答

1

試試這個

function resizeImage(width, height){ 
    var image = document.getElementById('resizeImage'), 
    canvas = document.createElement('canvas'), 
    ctx = canvas.getContext('2d'); 
    ctx.canvas.height = height;//pass height 
    ctx.canvas.width = width;//pass width 
    ctx.drawImage(image,cropLeft, cropTop, cropWidth, cropHeight,10,10,width,height); 
    return canvas; 
    }; 
+0

未捕獲的ReferenceError:cropHeight沒有定義 –

+0

@jayeshchaudhary你需要通過高度和寬度療法 – Manoj