導航:首頁 > 圖片大全 > 小程序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圖片如何預覽相關的資料

熱點內容
word圖片裁剪在哪兒 瀏覽:493
肛門的圖片男生 瀏覽:337
非主流頭像圖片男生 瀏覽:137
閨蜜文字圖片大全 瀏覽:271
美女在家運動的圖片 瀏覽:341
微信里發出去的圖片如何收回來 瀏覽:366
小學女孩穿短裙加白絲襪圖片 瀏覽:974
餘生最美的文字圖片 瀏覽:719
價格與質量圖片大全 瀏覽:86
圖片如何自然一點 瀏覽:79
花的圖片彩繪簡單 瀏覽:741
明星衣服搭配圖片夏天 瀏覽:274
那些年我們一起追的女孩的圖片 瀏覽:101
高清唯美動漫頭像男生頭像圖片 瀏覽:757
風箏輪價格和圖片 瀏覽:83
漂亮的女生上衣圖片 瀏覽:71
天秤桿圖片簡單 瀏覽:618
美女短身褲圖片大全 瀏覽:741
邁騰車上如何插小紅旗圖片 瀏覽:249
盆景價格圖片欣賞 瀏覽:465