当前位置:网站首页>Screenshot of the uniapp app and save it locally

Screenshot of the uniapp app and save it locally

2022-06-22 13:49:00 Amy's cat (silly steel)

down() {
    
    setTimeout(() => {
    
        let pages = getCurrentPages();
        let page = pages[pages.length - 1];
        let ws = page.$getAppWebview();
        let bitmap = new plus.nativeObj.Bitmap('drawScreen');
        //  take webview The content is drawn to Bitmap In the object  
        ws.draw(bitmap, () => {
    
            //  Save pictures to local  
            bitmap.save("_doc/drawScreen.jpg", {
    
                overwrite: true
            }, res => {
    
                console.log(res.target); //  Picture address  

                uni.saveImageToPhotosAlbum({
     // Save picture to system album .
                    filePath: res.target, // Image file path 
                    success: () => {
    
                        uni.showModal({
    
                            title: ' reminder ',
                            content: ' Picture saved successfully , Hurry to forward it to your friends ~',
                            showCancel: false,
                            confirmColor: "#34CE98",
                            confirmText: ' got it ',
                            success: () => {
    
                                this.canSave = false;
                            }
                        })
                        uni.hideLoading()
                    },
                    fail: function(e) {
    
                        uni.showModal({
    
                            title: ' reminder ',
                            content: ' Failed to save picture , Try again ~',
                            showCancel: false,
                            confirmColor: "#34CE98",
                            confirmText: ' got it ',
                            success: () => {
    
                                this.canSave = false;
                            }
                        })
                        uni.hideLoading()
                    }
                });

                bitmap.clear(); //  eliminate Bitmap object  
            }, error => {
    
                console.log(JSON.stringify(error)); //  Save failure information  
                uni.showModal({
    
                    title: ' reminder ',
                    content: ' Failed to save picture , Try again ~',
                    showCancel: false,
                    confirmColor: "#34CE98",
                    confirmText: ' got it ',
                    success: () => {
    
                        this.canSave = false;
                    }
                })
                uni.hideLoading()
                bitmap.clear(); //  eliminate Bitmap object  
            });
            // bitmap.clear(); //  eliminate Bitmap object  
        }, error => {
    
            uni.showModal({
    
                title: ' reminder ',
                content: ' Failed to save picture , Try again ~',
                showCancel: false,
                confirmColor: "#34CE98",
                confirmText: ' got it ',
                success: () => {
    
                    this.canSave = false;
                }
            })
            uni.hideLoading()
            console.log(JSON.stringify(error)); //  Drawing failed  
        }, {
    
            check: true, //  Set to detect white screen  
        });
    }, 2000)
}
原网站

版权声明
本文为[Amy's cat (silly steel)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221242184665.html