我是靠谱客的博主 美丽水池,这篇文章主要介绍小程序使用.getImageInfo()获取图片信息,现在分享给大家,希望可以做个参考。

这次给大家带来小程序使用.getImageInfo()获取图片信息,小程序使用.getImageInfo()获取图片信息的注意事项有哪些,下面就是实战案例,一起来看一下。

本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下

一.知识点

二.列子

(1).加载时

复制代码
1
2
3
4
<view class="zn-uploadimg"> <image src="{{tempFilePaths}}" mode="aspecFill" style="width: 100%; height: 450rpx" /> <text>图片的大小:{{imgwidth}}px*{{imgheight}}px</text> </view>
登录后复制
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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).上传图片时

复制代码
1
2
3
4
5
<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>
登录后复制
复制代码
1
2
3
4
5
6
.zn-uploadimg{ padding:1rem; } .zn-uploadimg image{ margin:1rem 0; }
登录后复制
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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, }) } }) } }) } })
登录后复制

相信看了本文案例你已经掌握了方法,更多精彩请关注靠谱客其它相关文章!

推荐阅读:

怎样开发微信小程序获取用户个人信息

Vue2.5与Element UI的组件分页功能实现

微信小程序的多文件下载封装使用

jquery动态添加和遍历option的方法

以上就是小程序使用.getImageInfo()获取图片信息的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是美丽水池最近收集整理的关于小程序使用.getImageInfo()获取图片信息的全部内容,更多相关小程序使用内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(107)

评论列表共有 0 条评论

立即
投稿
返回
顶部