华为机器canvas.drawImage后canvasToTemp图片大小不对?
发布于 5 年前 作者 liaomin 7743 次浏览 来自 官方Issues

设置canvas大小后,使用drawImage重绘图片大小,然后使用canvasToTempFilePath, 得到的图片,在模拟器上图片大小没问题,在华为荣耀9上的到的图片大小怎么就不对了?我将图片绘制成344px的width,但是华为机器得到的图片却是不固定的,模拟器上没有问题。代码片段如下:

wxml:

<view class=“canvasView”>

<canvas canvas-id=‘photo_canvas’ style=‘width:{{canvas_w}}px;height:{{canvas_h}}px’ class=‘myCanvas’></canvas>

</view>

js:

var towidth = 344;           //按宽度344px的比例压缩

var toheight = Math.trunc(344 * getImageInfoRes.height / getImageInfoRes.width);        //根据图片比例换算出图片高度

that.setData({

canvas_w: towidth,

canvas_h: toheight

})

ctx.drawImage(tempFilePaths, 0, 0, getImageInfoRes.width, getImageInfoRes.height, 0, 0, towidth, toheight)

ctx.draw(false, function () {

setTimeout(function () {

console.log(“draw finish”);

wx.canvasToTempFilePath({

canvasId: ‘photo_canvas’,

fileType: “jpg”,

quality:0.7,

1 回复

你好,可以关注一下新的canvas:小程序新 Canvas 接口公测? - 微信开放社区 https://developers.weixin.qq.com/community/develop/doc/00020a02c2c040114d19a398f5b001

上述问题麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

回到顶部