2017-05-31 31 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