<view>  
        <canvas canvas-id="myCanvas"></canvas>  
        <image :src="path" mode=""></image>  
        <button type="default" @click="open">拍照</button>  
    </view>  
</template>  
<script>  
export default {  
    data() {  
        return {  
            path: ''  
        };  
    },  
    methods: {  
        open() {  
            var ctx = uni.createCanvasContext('myCanvas', this);  
            var temp = this;  
            uni.chooseImage({  
                sourceType: ['camera'],  
                success(res) {  
                    uni.getImageInfo({  
                        src: res.tempFilePaths[0],  
                        success(s) {  
                            ctx.drawImage(res.tempFilePaths[0], 0, 0, s.width, s.height, 0, 0, uni.upx2px(750), uni.upx2px((750 * s.height) / s.width));  
                            ctx.save();  
                            ctx.setFontSize(14);  
                            ctx.setTextBaseline('bottom');  
                            ctx.setFillStyle('White');  
                            ctx.fillText('1233', 10, 20);  
                            ctx.draw(false, function(d) {  
                                uni.canvasToTempFilePath(  
                                    {  
                                        canvasId: 'myCanvas',  
                                        quality: 1,  
                                        success(ss) {  
                                            console.log(JSON.stringify(ss));  
                                        },  
                                        fail(f) {  
                                            console.log(JSON.stringify(f));  
                                        }  
                                    },  
                                    temp  
                                );  
                            });  
                        }  
                    });  
                },  
                fail(f) {  
                    console.log(f);  
                }  
            });  
        }  
    }  
};  
</script>  
<style></style>   
                                        
                                    
                                    - 发布:2020-11-27 11:41
- 更新:2020-12-01 18:01
- 阅读:1010
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win7旗舰版
HBuilderX类型: 正式
HBuilderX版本号: 2.9.8
手机系统: Android
手机系统版本号: Android 10
手机厂商: 华为
手机机型: HONOR 20 Liite LAR-AL00
页面类型: vue
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
                                    
                                    
                                         
                                
                                                                                                操作步骤:
                                    
                                        华为 HONOR 20 Liite LAR-AL00在没有升级成2020年10月1日的那个安全补丁包之前没有问题,升级完后 uni.canvasToTempFilePath走fail不走success,错误
{"errMsg":"canvasToTempFilePath:fail SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported."}
                                     
                                
                                                                                                华为 HONOR 20 Liite LAR-AL00在没有升级成2020年10月1日的那个安全补丁包之前没有问题,升级完后 uni.canvasToTempFilePath走fail不走success,错误
{"errMsg":"canvasToTempFilePath:fail SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported."}
预期结果:
                                    
                                    
                                        应该是走success能拿到图片地址
                                     
                                
                                                                                                应该是走success能拿到图片地址
实际结果:
                                    
                                    
                                        走的fail,{"errMsg":"canvasToTempFilePath:fail SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported."}
                                     
                                
                                                            走的fail,{"errMsg":"canvasToTempFilePath:fail SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported."}
bug描述:
华为 HONOR 20 Liite LAR-AL00在升级完2020年10月1日的安全补丁后,uni.canvasToTempFilePath走fail不走success,错误
{"errMsg":"canvasToTempFilePath:fail SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported."}
 
             
             
             
			 
                                                                     
            
s***@soian.com (作者)
版本是83.0.4103.106,是升级完安全补丁包才出现的,之前没有问题
2020-12-03 10:38
DCloud_UNI_LXH
回复 s***@soian.com: 可以更新最新的alpha版HBuilderX,华为手机canvas图片跨域问题已解决
2020-12-03 15:19
s***@soian.com (作者)
回复 DCloud_UNI_LXH: 这个正式版的大概什么时候更新,alpha版有时候还会引起其他问题,,零时处理了一下
2020-12-03 16:08
DCloud_UNI_LXH
回复 s***@soian.com: alpha转正式,时间上是不确定的,一般来说没有什么问题
2020-12-03 16:14
愿随风丶飘雪
回复 DCloud_UNI_LXH: H5+的程序也出现了这个问题 不更新app的情况下有办法解决吗
2020-12-11 20:08