介绍
这篇文章主要介绍了微信小程序wx.getImageInfo()获取图片信息的方法,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获、下面让小编带着大家一起了解一下。
<强>一。知识点强>
<强>二。列子
强>
(1)。加载时
& lt; view 类=皕n-uploadimg"祝辞,, & lt;才能image src=https://www.yisu.com/zixun/皗{tempFilePaths}}”模式=" aspecFill "/> <文本>图片的大小:{{imgwidth}} px * {{imgheight}} px 文本> 视图>
var app =, getApp (),, 页面({, ,,数据:{,, ,,,tempFilePaths:, & # 39; . ./上传/foods.jpg& # 39;,, ,,,imgwidth: 0,, ,,,imgheight: 0,,, ,,}, onReady才能:函数(){, ,,,//,页面渲染完成,, ,,,var _this =,,,, ,,,wx.getImageInfo ({, ,,,,,src:, _this.data.tempFilePaths,, ,,,,,成功:,function (res), {, ,,,,,,,_this.setData ({, ,,,,,,,,,imgwidth: res.width,, ,,,,,,,,,imgheight: res.height,, ,,,,,,,}), ,,,,,}, ,,,}),, ,,}, })
(2)。上传图片时
& lt; view 类=皕n-uploadimg"祝辞, & lt;才能button 类型=皃rimary" bindtap=癱hooseimage"在获取图片& lt;/button>,, & lt;才能image src=https://www.yisu.com/zixun/皗{tempFilePaths}}”模式=" aspecFill "/> <文本>图片的大小:{{imgwidth}} px * {{imgheight}} px 文本> 视图>
.zn-uploadimg {, 填充:1 rem;才能, }, {.zn-uploadimg 图像, 保证金才能:1 rem 0;, }
var app =, getApp (),, 页面({, ,,数据:{,, ,,,tempFilePaths:, & # 39; & # 39;,,, ,,,imgwidth: 0,, ,,,imgheight: 0,, ,,},/* *,才能, ,,*,上传图片, ,,*/, ,,chooseimage: function (), {,, ,,,var _this =,,,, ,,,wx.chooseImage ({,, ,,,,,数:,1,,//,默认9,, ,,,,,sizeType:,(& # 39;原始# 39;,,& # 39;压缩# 39;],,//,可以指定是原图还是压缩图,默认二者都有,, ,,,,,sourceType:,(& # 39;专辑# 39;,,& # 39;相机# 39;],,//,可以指定来源是相册还是相机,默认二者都有,, ,,,,,成功:,function (res), {,, ,,,,,,,//,返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片,, ,,,,,,,_this.setData ({,, ,,,,,,,,,tempFilePaths: res.tempFilePaths , ,,,,,,,}),, ,,,,,,,wx.getImageInfo ({, ,,,,,,,,,src:, res.tempFilePaths [0],, ,,,,,,,,,成功:,function (res), {, ,,,,,,,,,,,_this.setData ({, ,,,,,,,,,,,,,imgwidth: res.width,, ,,,,,,,,,,,,,imgheight: res.height,, ,,,,,,,,,,,}), ,,,,,,,,,}, ,,,,,,,}),, ,,,,,},, ,,,}),, ,,}, })
感谢你能够认真阅读完这篇文章,希望小编分享的“微信小程序wx.getImageInfo()获取图片信息的方法”这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!