原文:微信小程序把玩(三十二)Image API

选择图片时可设置图片是否是原图,图片来源。这用的也挺常见的,比如个人中心中设置头像,可以与wx.upLoadFile()API使用

主要方法:

wx.chooseImage(object)

wxml

<!--监听按钮-->
<button type="primary" bindtap="listenerButtonChooseImage">点击我选择相册</button>
<!--通过数据绑定的方式动态获取js数据-->
<image src="{{source}}" mode="aspecFill" style="width: 640rpx; height: 640rpx"/>

js

Page({
data:{
// text:"这是一个页面"
source: ''
},
/**
* 选择相册或者相机 配合上传图片接口用
*/
listenerButtonChooseImage: function() {
var that = this;
wx.chooseImage({
count: 1,
//original原图,compressed压缩图
sizeType: ['original'],
//album来源相册 camera相机
sourceType: ['album', 'camera'],
//成功时会回调
success: function(res) {
//重绘视图
that.setData({
source: res.tempFilePaths
})
}
})
},

wx.previewImage(object)

这又是一个奇葩API真实搞不懂怎么用这个。先模仿下官方咋使用但是没有效果,搞懂了在补充下自己的使用

wxml

<!--图片预览-->
<button type="primary" bindtap="listenerButtonPreviewImage">展示图片</button>

js

Page({
data:{
// text:"这是一个页面"
source: ''
}, /**
* 预览图片 又一个奇葩接口
*/
listenerButtonPreviewImage: function() {
wx.previewImage({
current: 'http://img.souutu.com/2016/0511/20160511055648316.jpg',
urls: [
'http://img.souutu.com/2016/0511/20160511055648316.jpg',
'http://img.souutu.com/2016/0511/20160511055650751.jpg',
'http://img.souutu.com/2016/0511/20160511054928658.jpg'
],
//这根本就不走
success: function(res) {
console.log(res);
},
//也根本不走
fail: function() {
console.log('fail')
}
})
} })

最新文章

  1. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q116-Q120)
  2. 原生java 压缩解压zip文件
  3. [KOJ95603]全球奥运
  4. ContentControl 与 ViewModel (二)
  5. FZU2165 v11(带权的重复覆盖)
  6. 20141109--SQL 练习题-1
  7. How to trace a java-program
  8. HDU 3501 Calculation 2(欧拉函数)
  9. 获取spring bean的utils
  10. CentOS 在同一窗口打开文件夹
  11. React问题集序
  12. 【新版】Android技术博客精华汇总
  13. patA1059 Prime Factors
  14. 1)django-建立步骤和目录说明
  15. jquery中ajax的写法
  16. PHP去除重复的数组数据
  17. 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字
  18. java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.pagehelper.Page
  19. HTML 删除和添加字
  20. NOIP模拟赛 双色球

热门文章

  1. [NPM] Add comments to your npm scripts
  2. AppStoreID--安装URL--应用更新URL--应用评分URL
  3. MFC下WM_NOTIFY消息处理流程
  4. 经典卷积神经网络的学习(三)—— Inception Net
  5. 入坑cordova
  6. H∞一般控制问题的鲁棒叙述性说明
  7. IdentityServer4实战 - 谈谈 JWT Token 的安全策略
  8. wpf绑定全局静态变量(mvvm)
  9. Extensible File System
  10. Android的APK文件的反编译方法【转】