lzrmie
lzrmie
  • 发布:2020-12-24 11:56
  • 更新:2020-12-24 11:56
  • 阅读:495

canvasToTempFilePath本地打包失效

分类:uni-app

1.直接运行可以触发方法

  1. 发行本地打包后,执行不了

    // 点击拍照  
            toDistinguish: debounce(function() {  
                var _this = this; // 选择或拍摄照片  
                uni.chooseImage({  
                    count: 1,  
                    sizeType: ['compressed'],  
                    success: (res) => {  
                        var photo = res; // 获取图片信息 方向  
                        uni.getImageInfo({  
                            src: photo.tempFilePaths[0],  
                            success: (res) => {  
                                var orientation = res.orientation;  
                                var canvasWidth = 375;  
                                var canvasHeight = 288;  
                                var ctx = uni.createCanvasContext('canvas', this);  
                                ctx.translate(canvasWidth / 2, canvasHeight / 2); // 根据图片方向进行旋转  
    
                                switch (orientation) {  
                                    case 'up':  
                                        break;  
    
                                    case 'right':  
                                        ctx.rotate(90 * Math.PI / 180);  
                                        break;  
    
                                    case 'left':  
                                        ctx.rotate(270 * Math.PI / 180);  
                                        break;  
    
                                    case 'down':  
                                        ctx.rotate(180 * Math.PI / 180);  
                                        break;  
                                }  
    
                                ctx.drawImage(res.path, -canvasWidth / 2, -canvasHeight / 2, canvasWidth, canvasHeight);  
                                ctx.draw(false, setTimeout(function() {  
                                    // canvas生成图片  
                                    uni.canvasToTempFilePath({  
                                        canvasId: 'canvas',  
                                        destWidth: canvasWidth,  
                                        destHeight: canvasHeight,  
                                        success: function(res) {  
                                            _this.SET_DISTINGUISHIMG(res.tempFilePath);  
                                            uni.navigateTo({  
                                                url: '../photo_distinguish/photo_distinguish?img=' + res.tempFilePath  
                                            });  
                                        },  
                                        fail: function(res) {  
                                            uni.showToast({  
                                                title: 'fail'  
                                            })  
                                        },  
                                        complete(res) {  
                                            uni.showToast({  
                                                title: 'complete'  
                                            })  
                                        }  
                                    });  
                                }, 1000));  
                            }  
                        });  
                    }  
                });  
            }, 1000, true)
2020-12-24 11:56 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复