微信小程序wx.getImageInfo()如何獲取圖片信息
本文實(shí)例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內(nèi)容如下
一.知識(shí)點(diǎn)

二.列子
(1).加載時(shí)
<view class="zn-uploadimg">
<image src="{{tempFilePaths}}" mode="aspecFill" style="width: 100%; height: 450rpx" />
<text>圖片的大?。簕{imgwidth}}px*{{imgheight}}px</text>
</view>
var app = getApp()
Page({
data: {
tempFilePaths: '../uploads/foods.jpg',
imgwidth:0,
imgheight:0,
},
onReady:function(){
// 頁面渲染完成
var _this = this;
wx.getImageInfo({
src: _this.data.tempFilePaths,
success: function (res) {
_this.setData({
imgwidth:res.width,
imgheight:res.height,
})
}
})
}
})

(2).上傳圖片時(shí)
<view class="zn-uploadimg">
<button type="primary"bindtap="chooseimage">獲取圖片</button>
<image src="{{tempFilePaths}}" mode="aspecFill" style="width: 100%; height: 450rpx"/>
<text>圖片的大?。簕{imgwidth}}px*{{imgheight}}px</text>
</view>
.zn-uploadimg{
padding:1rem;
}
.zn-uploadimg image{
margin:1rem 0;
}
var app = getApp()
Page({
data: {
tempFilePaths: '',
imgwidth:0,
imgheight:0,
},
/**
* 上傳圖片
*/
chooseimage: function () {
var _this = this;
wx.chooseImage({
count: 1, // 默認(rèn)9
sizeType: ['original', 'compressed'], // 可以指定是原圖還是壓縮圖,默認(rèn)二者都有
sourceType: ['album', 'camera'], // 可以指定來源是相冊還是相機(jī),默認(rèn)二者都有
success: function (res) {
// 返回選定照片的本地文件路徑列表,tempFilePath可以作為img標(biāo)簽的src屬性顯示圖片
_this.setData({
tempFilePaths:res.tempFilePaths
})
wx.getImageInfo({
src: res.tempFilePaths[0],
success: function (res) {
_this.setData({
imgwidth:res.width,
imgheight:res.height,
})
}
})
}
})
}
})

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript制作頁面倒計(jì)時(shí)器的實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了JavaScript制作頁面倒計(jì)時(shí)器的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-03-03
JavaScript高級(jí)程序設(shè)計(jì) 閱讀筆記(十八) js跨平臺(tái)的事件
js跨平臺(tái)的事件經(jīng)驗(yàn)分享,需要的朋友可以參考下2012-08-08
Bootstrap中表單控件狀態(tài)(驗(yàn)證狀態(tài))
這篇文章主要介紹了Bootstrap中表單控件狀態(tài)(驗(yàn)證狀態(tài)) 的相關(guān)資料,還給大家介紹了在Bootstrap框架中提供的機(jī)制驗(yàn)證效果,非常不錯(cuò),需要的朋友可以參考下2016-08-08
js關(guān)于精確計(jì)算和數(shù)值格式化以及直接引js文件
本文為大家介紹下關(guān)于精確計(jì)算和數(shù)值格式化以及直接引js文件,大家可以學(xué)習(xí)下2014-01-01
教你javascript如何獲取對(duì)象的key和value
獲取對(duì)象所有key的方法,需要使用?Object.keys(obj)?方法,Object.keys(obj)方返回一個(gè)數(shù)組,這個(gè)數(shù)組包含obj對(duì)象中的所有key,這篇文章主要介紹了javascript如何獲取對(duì)象的key和value,需要的朋友可以參考下2022-12-12

