JQuery调整大小后的图像画布只调整图像而不是画布

时间:2017-05-31 10:19:58

标签: javascript jquery html css canvas

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 个答案:

答案 0 :(得分: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;
  };