canvas.toDataURLWithMultiplier is not a function

一个人想着一个人 提交于 2019-12-02 10:44:59

问题


I am trying to export an image 4x the size of the canvas one.

With

var dataURL = canvas.toDataURL();

I get the image set to the size of the canvas

However when I try

var dataURL = canvas.toDataURLWithMultiplier(4);

I get the error "canvas.toDataURLWithMultiplier is not a function"

Here is my function below.

$('.preview').on('click touchstart', function() {

  // save canvas image as data url (png format by default)
  canvas.isGrabMode = false;
  canvas.setZoom(1.0);
  canvas.viewportTransform = [1, 0, 0, 1, 0, 0];
  // var dataURL = canvas.toDataURL();

  var dataURL = canvas.toDataURLWithMultiplier(4);
  // so it can be saved as an image
  document.getElementById('previewImg').src = dataURL;

  canvas.renderAll();

});

回答1:


var dataURL = canvas.toDataURL({
  format: 'png',
  multiplier: 4
});

Use multiplier property in toDataURL().



来源:https://stackoverflow.com/questions/49647509/canvas-todataurlwithmultiplier-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!