收藏
回答

真机canvasToTempFilePath:fail :create bitmap failed?

基础库信息看图,代码片段:https://developers.weixin.qq.com/s/qVtsctm97BVq,记得开启不校验域名

const drawImageByUrl = (imgData, slef) => {
    return new Promise((rolve) => {
        ctx = wx.createCanvasContext('myCanvas', slef);
        console.log(ctx, 'ctx');
        // ctx = Canvas.getContext('2d'); 
        // 开始绘制
        const colorList = ['#229241''#e64032''#d7aa1c''#3c8af0''#f46502''#99cc75''#001b30''#bc1616'];
        wx.getImageInfo({
            src: imgData.img,
            success(res) => {
                const imgWidth = res.width; // 图片原始宽度  
                const imgHeight = res.height; // 图片原始高度  
                console.log(res, '图片宽高resres');
                // 绘制图片  
                ctx.drawImage(res.path, 00, imgWidth, imgHeight);
                if (imgData.locate && imgData.locate.length > 0) {
                    imgData.locate.map((item, idx) => {
                        const color = colorList[idx];
                        if (item.box && item.box.length > 0) {
                            let x1 = item.box[0],
                                y1 = item.box[1],
                                x2 = item.box[2],
                                y2 = item.box[3];
                            // x1, y1, x2, (y2 = ((x1 / 1000) * w, (y1 / 1000) * h, (x2 / 1000) * w, (y2 / 1000) * h));
                            x1 = (x1 / 1000) * imgWidth;
                            y1 = (y1 / 1000) * imgHeight;
                            x2 = (x2 / 1000) * imgWidth;
                            y2 = (y2 / 1000) * imgHeight;
                            const width = x2 - x1,
                                height = y2 - y1;
                            // 画矩形
                            drawRectangle(x1, y1, width, height, color);
                            // 标注
                            if (item.ref) drawText(item.ref, x1, y1, color);
                        }
                    });
                    // setTimeout(() => {
                    //     const imgresult = ctx.toDataURL('image/png');
                    //     return {
                    //         url: imgresult
                    //     }
                    // }, 500);
                }
                //输出图片
                ctx.draw(false,()=>{
                    setTimeout(()=>{
                        wx.canvasToTempFilePath({
                            canvasId'myCanvas',
                            // canvas: ctx, //画布标识,传入 canvas 组件实例 (canvas type="2d" 时使用该属性)。
                            width: imgWidth, //指定的画布区域的宽度
                            height: imgHeight, //指定的画布区域的高度
                            destWidth: imgWidth, //输出的图片的宽度
                            destHeight: imgHeight, //输出的图片的高度
                            success(result) => {
        
                                var tempFilePath = result.tempFilePath;
                                rolve(tempFilePath)
                            },
                            failfunction (error{
                                console.log(error);
                            }
                        }, slef);
                    },500)
                })


            },
            failfunction (err{
                console.error('Failed to get image info:', err);
            }
        });
    })
}


最后一次编辑于  11-05
回答关注问题邀请回答
收藏

2 个回答

  • Demons
    Demons
    11-19

    测试正常

    11-19
    有用
    回复 2
    • June
      June
      11-20
      你好,请问下你这边的基础库是多少,我们这边真机都没有出现图片
      11-20
      回复
    • Demons
      Demons
      11-22回复June
      3.6.3,你是什么版本
      11-22
      回复
  • June
    June
    11-05

    在开发工具没问题可以正常绘制图片, 电脑和手机上就会报错

    11-05
    有用
    回复
登录 后发表内容