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

熱點內容
國外女孩頭像圖片真人 瀏覽:391
滑頭鬼之孫圖片高清唯美 瀏覽:550
連起來的文字圖片4張 瀏覽:834
電腦上傳圖片怎麼不顯示桌面 瀏覽:662
女生手鏈金手鐲圖片 瀏覽:476
阿狸可愛卡通人物圖片 瀏覽:974
怎麼樣對齊word圖片 瀏覽:355
公主裙怎麼畫簡單又漂亮圖片大全 瀏覽:792
新浪微博怎麼發長圖片 瀏覽:672
裁剪迷你衣服圖片 瀏覽:643
花樣2017新娘發型圖片 瀏覽:747
九九重陽節手抄報圖片大全 瀏覽:190
招手女孩圖片 瀏覽:601
word插入圖片怎麼消除 瀏覽:246
ps上百張圖片怎麼做成一張長圖 瀏覽:373
賣男裝的女孩圖片 瀏覽:289
紫藤花盆景圖片大全 瀏覽:493
圖片壁紙動漫男生專用 瀏覽:620
最新虐心文字說說圖片 瀏覽:191
男生j圖片大全 瀏覽:652