当前位置:首页站长学院后端开发小程序使用.getImageInfo()获取图片信息
企业营销,就选知企PROSAAS

小程序使用.getImageInfo()获取图片信息

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

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

一.知识点

小程序使用.getImageInfo()获取图片信息

二.列子

(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, 
        }) 
      } 
    })  
  }  
})

小程序使用.getImageInfo()获取图片信息

(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, 
            }) 
          } 
        })  
      }  
    })  
  }  
})

小程序使用.getImageInfo()获取图片信息

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

推荐阅读:

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

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

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

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

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

温馨提示:

文章标题:小程序使用.getImageInfo()获取图片信息

文章链接:https://ceshi.prosaas.cn/17677.html

更新时间:2018年03月23日

声明: 本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:973664285@qq.com我们将第一时间处理! 资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。 所有资源仅限于参考和学习,版权归原作者所有,更多请阅读知企PROSAAS协议

给TA打赏
共{{data.count}}人
人已打赏
后端开发

在小程序里实现animation动画

2018-3-23 10:57:39

后端开发

微信小程序实现与后台PHP交互

2018-3-29 11:39:54

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索