canvas.toDataURLWithMultiplier 不是函数 [英] canvas.toDataURLWithMultiplier is not a function

查看:22
本文介绍了canvas.toDataURLWithMultiplier 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试导出 4 倍于画布大小的图像.

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

var dataURL = canvas.toDataURL();

我将图像设置为画布的大小

I get the image set to the size of the canvas

但是当我尝试时

var dataURL = canvas.toDataURLWithMultiplier(4);

我收到错误canvas.toDataURLWithMultiplier 不是函数"

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

下面是我的函数.

$('.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();

});

推荐答案

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

toDataURL()multiplier 属性>.

Use multiplier property in toDataURL().

这篇关于canvas.toDataURLWithMultiplier 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆