3***@qq.com
3***@qq.com
  • 发布:2025-05-21 09:31
  • 更新:2025-05-21 09:31
  • 阅读:16

【报Bug】uni.canvasToTempFilePath 没有返回

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: windows11

HBuilderX类型: 正式

HBuilderX版本号: 4.66

手机系统: Android

手机系统版本号: Android 7.0

手机厂商: 华为

手机机型: 华为P9 eva-al00

页面类型: nvue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

drawCanvas() {
var ctx = uni.createCanvasContext('myCanvas')
var that=this;
// begin path
ctx.rect(10, 10, 100, 30)
ctx.setFillStyle('yellow')
ctx.fill()

            // begin another path    
            ctx.beginPath()    
            ctx.rect(10, 40, 100, 30)    

            // only fill this rect, not in current path    
            ctx.setFillStyle('blue')    
            ctx.fillRect(10, 70, 100, 30)    

            ctx.rect(10, 100, 100, 30)    

            // it will fill current path    
            ctx.setFillStyle('red')    
            ctx.fill()   
            ctx.draw(true, (() => {    
            setTimeout(()=>{  
                console.log('asas');  
                uni.canvasToTempFilePath({  
                  x: 100,  
                  y: 200,  
                  width: 50,  
                  height: 50,  
                  destWidth: 100,  
                  destHeight: 100,  
                  canvasId: 'myCanvas',  
                  success: function(res) {  
                    // 在H5平台下,tempFilePath 为 base64  
                    console.log(res.tempFilePath)  
                  },  
                  complete:function(res) {  
                      console.log('c');  
                }  
                },that)  
            },1000);  
            })());  

        }  

success 、complete、fail 都不执行。

操作步骤:
<template>    
    <view>    
        <view>canvas to temp file path</view>    
        <canvas style="width: 300px; height: 200px;border: 1px solid red;" id="myCanvas"  ref="myCanvas" canvas-id="myCanvas"></canvas>    
    </view>    
</template>    

<script>    
    export default {    
        data() {    
            return {  
                aaa:'aaa'  
            }    
        },    
        methods: {    
            drawCanvas() {    
                var ctx = uni.createCanvasContext('myCanvas')   
        var that=this;  
                // begin path    
                ctx.rect(10, 10, 100, 30)    
                ctx.setFillStyle('yellow')    
                ctx.fill()    

                // begin another path    
                ctx.beginPath()    
                ctx.rect(10, 40, 100, 30)    

                // only fill this rect, not in current path    
                ctx.setFillStyle('blue')    
                ctx.fillRect(10, 70, 100, 30)    

                ctx.rect(10, 100, 100, 30)    

                // it will fill current path    
                ctx.setFillStyle('red')    
                ctx.fill()   
                ctx.draw(false, (() => {    
                setTimeout(()=>{  
                    console.log('asas');  
                    uni.canvasToTempFilePath({  
                      x: 100,  
                      y: 200,  
                      width: 50,  
                      height: 50,  
                      destWidth: 100,  
                      destHeight: 100,  
                      canvasId: 'myCanvas',  
                      success: function(res) {  
                        // 在H5平台下,tempFilePath 为 base64  
                        console.log(res.tempFilePath)  
                      },  
                      complete:function(res) {  
                          console.log('c');  
                    }  
                    },that)  
                },1000);  
                })());  

            }  
},  
        onReady() {    
           this.drawCanvas();  
        }    
    }    
</script>    

<style>    
</style>

预期结果:

应该console.log('c');

实际结果:

回调函数没有返回,不知什么执行情况。canvas里也没有展现画图效果

bug描述:

uni.canvasToTempFilePath 这个方法,按官网范例不执行。

2025-05-21 09:31 负责人:无 分享
已邀请:

要回复问题请先登录注册