y***@163.com
y***@163.com
  • 发布:2022-07-19 11:36
  • 更新:2022-07-19 17:10
  • 阅读:508

uni.canvasToTempFilePath导出的地址赋值到image的src中为啥不显示图片,h5和app都不显示

分类:uni-app
<template>  
    <view>  
        <view><canvas id="myCanvas" canvas-id="myCanvas" :style="{ width: windowWidth + 'px', height: windowHeight + 'px' }"></canvas></view>  
        <view><image :src="photo"></image></view>  
    </view>  
</template>  

<script>  
export default {  
    data() {  
        return {  
            windowWidth: '',  
            windowHeight: '',  
            photo: ''  
        };  
    },  
    onLoad() {  
        let res = getApp().globalData.systemInfo;  
        this.windowWidth = res.windowWidth ;  
        this.windowHeight = (res.windowHeight - 80) / 5;  
    },  
    onReady() {  
        this.testCtx();  
    },  
    methods: {  
        testCtx() {  
            const ctx = uni.createCanvasContext('myCanvas', this);  
            ctx.moveTo(10, 10);  
            ctx.rect(10, 10, 100, 50);  
            ctx.lineTo(110, 60);  
            ctx.stroke();  
            ctx.draw();  

            uni.canvasToTempFilePath({  
                canvasId: 'myCanvas',  
                success: function(res) {  
                    // this.photo = res.tempFilePath;  
                    this.photo = 'file://' + res.tempFilePath;  
                    console.log(this.photo);  
                }  
            });  
        }  
    }  
};  
</script>  

<style>  
image {  
    background-color: gray;  
    width: 400px;  
    height: 500px;  
}  
</style>  
2022-07-19 11:36 负责人:无 分享
已邀请:
FullStack

FullStack - 【插件开发】【专治疑难杂症】【ios上架、马甲包、白包、过审、已成功上架过几百个】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=22130】【非诚勿扰】QQ:543610866

去 文件管理器 里,找到这张照片,然后发出来

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