導航:首頁 > 圖片大全 > 小程序src圖片如何預覽

小程序src圖片如何預覽

發布時間:2025-02-18 06:09:50

1. 小程序怎麼臨時載入本地相冊圖片

小程序中獲取圖片可通過兩種方式得到,第一種是直接打開微信內部自己的樣式,第一格就是相機拍照,後面是圖片,第二種是彈框提示用戶是要拍照還是從相冊選擇,下面一一來看。

選擇相冊要用到wx.chooseImage(OBJECT)函數,具體參數如下:

直接來看打開相機相冊的代碼:

Page({ data: { tempFilePaths: '' }, onLoad: function () { }, chooseimage: function () { var that = this; wx.chooseImage({ count: 1, // 默認9 sizeType: ['original', 'compressed'], // 可以指定是原圖還是壓縮圖,默認二者都有 sourceType: ['album', 'camera'], // 可以指定來源是相冊還是相機,默認二者都有 success: function (res) { // 返回選定照片的本地文件路徑列表,tempFilePath可以作為img標簽的src屬性顯示圖片 that.setData({ tempFilePaths: res.tempFilePaths }) } }) }, })

方法一效果圖如下:

點擊獲取彈框提示,代碼如下:

Page({ data: { tempFilePaths: '' }, onLoad: function () { }, chooseimage: function () { var that = this; wx.showActionSheet({ itemList: ['從相冊中選擇', '拍照'], itemColor: "#CED63A", success: function (res) { if (!res.cancel) { if (res.tapIndex == 0) { that.chooseWxImage('album') } else if (res.tapIndex == 1) { that.chooseWxImage('camera') } } } }) }, chooseWxImage: function (type) { var that = this; wx.chooseImage({ sizeType: ['original', 'compressed'], sourceType: [type], success: function (res) { console.log(res); that.setData({ tempFilePaths: res.tempFilePaths[0], }) } }) } })

文件的臨時路徑,在小程序本次啟動期間可以正常使用,如需持久保存,需在主動調用 wx.saveFile,在小程序下次啟動時才能訪問得到。

布局文件:

<button style="margin:30rpx;" bindtap="chooseimage">獲取圖片</button> <image src="{{tempFilePaths }}" catchTap="chooseImageTap" mode="aspectFit" style="width: 100%; height: 450rpx" />

閱讀全文

與小程序src圖片如何預覽相關的資料

熱點內容
心痛女孩子的動態圖片 瀏覽:21
女孩白色內內圖片 瀏覽:50
入冬早上好文字圖片 瀏覽:495
帥氣男生換裝圖片 瀏覽:89
短發面條卷發型圖片 瀏覽:881
可愛小孩子圖片賣萌 瀏覽:518
花的圖畫手繪簡單圖片 瀏覽:636
動漫公主服裝圖片大全圖片大全 瀏覽:44
動漫繪畫作品圖片 瀏覽:16
小女孩幾幾的現狀圖片 瀏覽:133
櫻花圖片動漫圖 瀏覽:632
成熟潮男搭配衣服圖片 瀏覽:41
動漫人物圖片大全黑白 瀏覽:969
最多動漫圖片 瀏覽:731
小鳥衣服圖片大全可愛 瀏覽:394
手擋太陽的圖片女生 瀏覽:436
男女生圖片背影圖片 瀏覽:963
想太多心會累文字圖片 瀏覽:310
簡單動漫圖片教程視頻 瀏覽:504
女孩發育圖片視頻 瀏覽:502