微信小程序wx.getImageInfo()获取图片信息
来源:互联网 发布:塑料水晶高跟鞋淘宝 编辑:程序博客网 时间:2024/03/28 23:23
一.知识点
二.列子
(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, }) } }) } }) } })
阅读全文
0 1
- 微信小程序wx.getImageInfo()获取图片信息
- wx.getImageInfo详解-图片-媒体API-微信小程序API-微信小程序开发教程
- 微信小程序wx.previewImage预览图片
- 微信小程序-wx.request获取数据
- wx.userinfo获取不到信息
- 微信小程序wx.request接收服务器返回信息
- 小程序使用wx.chooseAddress获取用户手机号码,微信chooseAddress接口获取收货信息
- 微信小程序wx.upload上传图片后台java
- 微信小程序 wx.request 获取百度API token
- 微信小程序-wx.uploadFile
- 微信小程序 wx:for
- 微信小程序 wx:key
- 微信小程序 wx:key
- 微信小程序 wx.showToast()
- 微信小程序--wx:for
- 微信小程序 (wx.chooseImage)
- 微信小程序wx.request程序
- 小程序wx.getUserInfo获取用户信息
- 设在vim自动换行等功能的方法
- 二叉树的递归和非递归遍历(java)
- OpenCV学习笔记(6)图像的缩放
- C++递推算法之菲波拉契数列
- 基于Tcl/Tk语言的自动化测试平台的实现
- 微信小程序wx.getImageInfo()获取图片信息
- UNIX/Linux_C_程序员需要掌握的七种武器
- AngularJS 中利用 Interceptors 来统一处理 HTTP 的错误
- MYSQL初学者使用指南
- django+nginx+uwsgi 部署问题
- 阿里云服务器配置FTP账号
- HDU
- 找出这个数(难度:半颗星)
- GO语言通用生产消费模型