9
微信小程序开发实战(26):获取图像信息
source link: https://blog.csdn.net/nokiaguy/article/details/108289562
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
微信小程序开发实战(26):获取图像信息
wx.getImageInfo方法可以获取图像的宽度、高度和路径。其中宽度和高度单位是物理像素。使用该方法时,需要使用src属性,用来指定用来获取信息的图像文件名。src属性可以指定内嵌到小程序中的图像,也可以指定通过wx.chooseImage方法选择的图像。
首先在pages目录中建立一个images子目录,然后放置一个pic.png图像文件,目录结构如图1所示。
图1 pic.png图像的位置
我们可以使用下面的代码获取pic.png图像的信息。
执行这段代码后,会在Console中输出如图2所示的信息。
图2 输出pic.png文件的相关信息
我们也可以使用下面的代码获取使用wx.chooseImage方法选择的图像的信息。
选择一个图像后,会在Console中输出如图3所示的图像信息。
图3 获取选择的图像的信息
对本文感兴趣,可以加李宁老师微信公众号(unitymarvel):
关注 「极客起源」 公众号,获得更多免费技术视频和文章。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK