国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

uniapp 微信小程序保存圖片到系統(tǒng)相冊(cè)( 獲取用戶是否開(kāi)啟 授權(quán)保存圖片到相冊(cè)。)

這篇具有很好參考價(jià)值的文章主要介紹了uniapp 微信小程序保存圖片到系統(tǒng)相冊(cè)( 獲取用戶是否開(kāi)啟 授權(quán)保存圖片到相冊(cè)。)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

1.預(yù)覽效果圖

uniapp獲取相冊(cè)權(quán)限,微信小程序,uni-app,小程序

uniapp獲取相冊(cè)權(quán)限,微信小程序,uni-app,小程序

當(dāng)用戶點(diǎn)擊拒絕按鈕后的截圖:

?uniapp獲取相冊(cè)權(quán)限,微信小程序,uni-app,小程序

用戶點(diǎn)擊不授權(quán)? 則關(guān)閉彈窗

單獨(dú)給用戶點(diǎn)擊授權(quán)后, 跳轉(zhuǎn)到授權(quán)頁(yè)面

uniapp獲取相冊(cè)權(quán)限,微信小程序,uni-app,小程序

?開(kāi)啟授權(quán)后:

uniapp獲取相冊(cè)權(quán)限,微信小程序,uni-app,小程序文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-719064.html

2.代碼?

<template>
    <view class="download_certificate">
        <view class="img">
            <!-- <view class="certificate_img"> -->
            <!-- <image src="cloud://produce-6gykelggdea632cb.7072-produce-6gykelggdea632cb-1317432646/download.png"/> -->
            <view style="width: 700rpx; height: 500rpx" @click="open">
                <canvas type="2d" id="myCanvas" style="width: 100%; height: 100%" />
            </view>
            <!-- </view> -->

            <view style="position: absolute; bottom: 200rpx; left: 1rpx; width: 100%; height: auto">
                <button
                    style="width: 90%; height: 120rpx; background: #df3535; border-radius: 20rpx; line-height: 120rpx; font-size: 36rpx; font-weight: 500; color: #ffffff"
                    size="large"
                    type="default"
                    @tap.native="savaImage"
                >
                    保存到相冊(cè)
                </button>
            </view>
        </view>

        <view class="popup">
            <!-- 遮罩層開(kāi)始 -->
            <uni-popup ref="popup" :mask-click="false">
                <text> 11 </text>
                <button @click="close" safe-area="true" style="width: 100vm; height: 100vh">關(guān)閉</button>
            </uni-popup>
            <!-- 遮罩層結(jié)束 -->
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            src: 'https://cdn-asset.znyzf.com/asset/zsbg.jpg',
            canvasRef: null,
            info: {},
            number: 1
        }
    },
    created() {
        this.drawCanvas()
    },
    onLoad(options) {
        this.info = JSON.parse(decodeURIComponent(options.certificateInfo))
        this.drawCanvas()
    },
    methods: {
        savaImage() {
            let that = this
            uni.getSetting({
                success(res) {
                    if (!res.authSetting['scope.writePhotosAlbum']) {
                        uni.authorize({
                            scope: 'scope.writePhotosAlbum',
                            success(res) {
                                that.saveImg()
                            },
                            fail() {
                                uni.showModal({
                                    content: '請(qǐng)?jiān)试S相冊(cè)權(quán)限,拒絕將無(wú)法正常使用小程序',
                                    showCancel: false,
                                    success() {
                                        uni.openSetting({
                                            success(settingdata) {
                                                if (settingdata.authSetting['scope.writePhotosAlbum']) {
                                                } else {
                                                    console.log('獲取權(quán)限失敗')
                                                }
                                            }
                                        })
                                    }
                                })
                            }
                        })
                    } else {
                        that.saveImg()
                    }
                }
            })
        },

        drawCanvas() {
            const query = uni.createSelectorQuery()
            query
                .select('#myCanvas')
                .fields({
                    node: true,
                    size: true
                })
                .exec((res) => {
                    const canvas = res[0].node
                    const ctx = canvas.getContext('2d')
                    this.canvasRef = canvas
                    const dpr = uni.getSystemInfoSync().pixelRatio
                    canvas.width = res[0].width * dpr // 獲取寬
                    canvas.height = res[0].height * dpr // 獲取高
                    ctx.scale(dpr, dpr)
                    // 到這里就可以直接繪制
                    let image = canvas.createImage() //創(chuàng)建iamge實(shí)例
                    image.src = this.src // 引入本地圖片
                    image.onload = (imginfo) => {
                        // 獲取http圖片寬高
                        // const {width,height} = imginfo.path[0];
                        // const aspect = width / height;
                        // console.log(width,height)
                        const currentWidth = canvas.width / dpr
                        const currentHeight = canvas.height / dpr
                        console.log(currentWidth, currentHeight)
                        ctx.drawImage(image, 0, 0, currentWidth, currentHeight)
                        // ctx.drawImage(image, 0, 0, canvas.width / dpr, canvas.height / dpr); // 背景圖
                        ctx.fillStyle = '#000000'
                        ctx.font = '16px Arial'
                        ctx.textAlign = 'center'
                        ctx.fillText(this.info['name'] || '剛剛', 0.235 * currentWidth, 0.45 * currentHeight, 100) //字體的位置/設(shè)備的大小
                        ctx.textAlign = 'left'
                        ctx.font = '9px Arial'
                        ctx.fillText(this.info['code'] || '456', 0.434 * currentWidth, 0.786 * currentHeight)
                        //年月日
                        ctx.font = '10px Arial'
                        ctx.fillText(this.info['beforeYear'], 0.247 * currentWidth, 0.555 * currentHeight)
                        ctx.fillText(this.info['beforeMonth'], 0.37 * currentWidth, 0.555 * currentHeight)
                        ctx.fillText(this.info['beforeDay'], 0.445 * currentWidth, 0.555 * currentHeight)
                        ctx.fillText(this.info['afterYear'], 0.55 * currentWidth, 0.555 * currentHeight)
                        ctx.fillText(this.info['afterMonth'], 0.675 * currentWidth, 0.555 * currentHeight)
                        ctx.fillText(this.info['afterDay'], 0.75 * currentWidth, 0.555 * currentHeight)
                    }
                })
        },

        saveImg() {
            let that = this
            uni.showLoading({
                title: '生成中...'
            })
            uni.canvasToTempFilePath({
                canvas: that.canvasRef,
                x: 0,
                y: 0,
                width: that.canvasWidth * 2,
                height: that.canvasHeight * 2,
                destWidth: that.canvasWidth * 2,
                destHeight: that.canvasHeight * 2,
                success: (res) => {
                    uni.saveImageToPhotosAlbum({
                        filePath: res.tempFilePath,
                        success: (res) => {
                            // console.log(this.saveTempFilePath)
                            uni.showModal({
                                title: '保存成功!',
                                content: '圖片已保存到本地相冊(cè)',
                                showCancel: false,
                                success: (res) => {
                                    if (res.confirm) {
                                        uni.showToast({
                                            title: '圖片保存成功'
                                        })
                                    }
                                }
                            })
                        },
                        fail: (err) => {
                            console.log(err)
                        }
                    })
                },
                fail: (err) => {
                    console.log(err)
                }
            })
            setTimeout(() => {
                uni.hideLoading()
            }, 1000)
        },

        // 遮罩層相關(guān)的回調(diào)
        open() {
            this.$refs.popup.open('top')
        },
        close() {
            this.$refs.popup.close()
        }
    }
}
</script>
<style>
.download_certificate {
    padding: 40rpx 30rpx;
}

.certificate_img {
    width: 100%;
}

.certificate_img image {
    width: 100%;
}
</style>

到了這里,關(guān)于uniapp 微信小程序保存圖片到系統(tǒng)相冊(cè)( 獲取用戶是否開(kāi)啟 授權(quán)保存圖片到相冊(cè)。)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 微信小程序保存圖片到相冊(cè) 微信小程序?qū)崿F(xiàn)將圖片保存到手機(jī)相冊(cè)(方案一)

    目錄 微信小程序?qū)崿F(xiàn)將圖片保存到手機(jī)相冊(cè)(方案一) 微信小程序?qū)崿F(xiàn)將圖片保存到手機(jī)相冊(cè)(方案二) 微信小程序之點(diǎn)擊復(fù)制文本到剪貼板 微信小程序---判斷是IOS還是安卓 微信小程序分享圖片給微信好友 首先我們需要調(diào)用wx.downloadFile方法下載文件資源到本地,然后利用

    2023年04月20日
    瀏覽(21)
  • 微信小程序保存圖片到相冊(cè) 微信小程序?qū)崿F(xiàn)將圖片保存到手機(jī)相冊(cè)(方案一)

    目錄 微信小程序?qū)崿F(xiàn)將圖片保存到手機(jī)相冊(cè)(方案一) 微信小程序?qū)崿F(xiàn)將圖片保存到手機(jī)相冊(cè)(方案二) 微信小程序之點(diǎn)擊復(fù)制文本到剪貼板 微信小程序---判斷是IOS還是安卓 微信小程序分享圖片給微信好友 首先我們需要調(diào)用wx.downloadFile方法下載文件資源到本地,然后利用

    2023年04月20日
    瀏覽(25)
  • 微信小程序?qū)崿F(xiàn)將圖片保存到手機(jī)相冊(cè)

    首先我們需要調(diào)用 wx.downloadFile 方法下載文件資源到本地,然后利用 wx.saveImageToPhotosAlbum 方法保存圖片到系統(tǒng)相冊(cè),需要注意的是這樣寫(xiě)很可能會(huì)因?yàn)闆](méi)有權(quán)限而導(dǎo)致下載不了圖片,所以我們最后還需要給接口一個(gè)調(diào)用失敗的回調(diào)函數(shù),以此來(lái)獲取權(quán)限,最后這個(gè)小功能就實(shí)

    2024年02月11日
    瀏覽(46)
  • 微信小程序——保存圖片到手機(jī)相冊(cè)(代碼詳解)

    首先我們要知道,如果小程序首次發(fā)起授權(quán)被拒絕之后,再次點(diǎn)擊同一個(gè)按鈕執(zhí)行的wx.authorize(...)不會(huì)再?gòu)棾鍪跈?quán)窗口。所以我們需要到引導(dǎo)用戶到設(shè)置頁(yè)面進(jìn)行手動(dòng)授權(quán)。 引導(dǎo)用戶到設(shè)置頁(yè)面授權(quán)的方式有兩種: 第一種: 使用小程序api :wx.openSetting(...)打開(kāi)設(shè)置頁(yè)面 第二

    2024年02月04日
    瀏覽(32)
  • 微信小程序-生成canvas圖片并保存到手機(jī)相冊(cè)

    wxml頁(yè)面 wxss頁(yè)面 js代碼

    2024年02月10日
    瀏覽(28)
  • 微信小程序canvas畫(huà)布圖片保存到相冊(cè)官方授權(quán)、自定義授權(quán)、保存

    目錄 關(guān)鍵步驟介紹 Component實(shí)現(xiàn)自定義授權(quán)彈框 wx.getSetting可以獲取授權(quán)信息。 wx.authorize首次授權(quán)時(shí)會(huì)打開(kāi)彈框讓用戶授權(quán),若用戶已選擇同意或拒絕,后續(xù)不會(huì)再顯示授權(quán)彈框。 如果授權(quán)信息顯示未進(jìn)行相冊(cè)授權(quán),則打開(kāi)自定義彈框(show_auth: true)讓用戶選擇是否自行配置

    2024年01月16日
    瀏覽(30)
  • 微信小程序canvas畫(huà)布繪制base64圖片并保存圖片到相冊(cè)中

    WXML部分: 樣式可以根據(jù)自己需求自行調(diào)整 canvas繪制成圖片部分: 這就將圖片繪制出來(lái)了。 首先獲取用戶相冊(cè)權(quán)限。 保存功能:

    2024年02月13日
    瀏覽(35)
  • uniapp開(kāi)發(fā)微信小程序使用painter將頁(yè)面轉(zhuǎn)換為圖片并保存到本地相冊(cè)

    uniapp開(kāi)發(fā)微信小程序使用painter將頁(yè)面轉(zhuǎn)換為圖片并保存到本地相冊(cè)

    我使用到painter的原因是,在uniapp開(kāi)發(fā)微信小程序時(shí),需要將一個(gè)頁(yè)面的內(nèi)容轉(zhuǎn)換成圖片保存到本地相冊(cè)。 起初在網(wǎng)上找到很多都是在 uniapp 中使用 html2canvas 將 網(wǎng)頁(yè)轉(zhuǎn)換成圖片再 jspdf 將圖片轉(zhuǎn)換為pdf ,但是這種方式在小程序環(huán)境不支持,只在 h5 環(huán)境下適用, 當(dāng)然這個(gè)方式是

    2024年02月12日
    瀏覽(29)
  • 微信小程序海報(bào)插件Painter 2.0(canvas畫(huà)圖)使用并保存圖片到相冊(cè)案例

    Painter通過(guò) json 數(shù)據(jù)形式,來(lái)進(jìn)行動(dòng)態(tài)渲染并繪制出圖片。 Painter 的優(yōu)勢(shì) 功能全,支持文本、圖片、矩形、qrcode 類型的 view 繪制 布局全,支持多種布局方式,如 align(對(duì)齊方式)、rotate(旋轉(zhuǎn)) 支持圓角,其中圖片,矩形,和整個(gè)畫(huà)布支持 borderRadius 來(lái)設(shè)置圓角 支持邊框,

    2024年01月20日
    瀏覽(102)
  • uniapp-小程序保存圖片到相冊(cè)

    uniapp-小程序保存圖片到相冊(cè)

    一. 將圖片保存到手機(jī)相冊(cè)涉及的 api 有以下幾個(gè) 1. uni.getSetting (獲取用戶的當(dāng)前設(shè)置) 2. uni.authorize (提前向用戶發(fā)起授權(quán)請(qǐng)求。調(diào)用后會(huì)立刻彈窗詢問(wèn)用戶是否同意授權(quán)小程序使用某項(xiàng)功能或獲取用戶的某些數(shù)據(jù),但不會(huì)實(shí)際調(diào)用對(duì)應(yīng)接口。如果用戶之前已經(jīng)同意授權(quán),則不

    2024年04月22日
    瀏覽(26)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包