您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 伊春分类信息网,免费分类信息发布

在微信小程序中如何才能获取图片信息

2024/4/6 20:14:50发布5次查看
这篇文章主要为大家详细介绍了微信小程序wx.getimageinfo()如何获取图片信息,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了android九宫格图片展示的具体代码,供大家参考,具体内容如下
一.知识点
二.列子
(1).加载时
<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).上传图片时
<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, // 默认9 sizetype: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourcetype: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { // 返回选定照片的本地文件路径列表,tempfilepath可以作为img标签的src属性显示图片 _this.setdata({ tempfilepaths:res.tempfilepaths }) wx.getimageinfo({ src: res.tempfilepaths[0], success: function (res) { _this.setdata({ imgwidth:res.width, imgheight:res.height, }) } }) } }) } })
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
vux如何实现上拉刷新功能
vue中如何实现methods方法之间调用
vue中如何使用element-ui的upload上传组件
以上就是在微信小程序中如何才能获取图片信息的详细内容。
伊春分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录