选择图片时可设置图片是否是原图,图片来源。这用的也挺常见的,比如个人中心中设置头像,可以与wx.upLoadFile()API使用
主要方法:
wx.chooseImage(object)
wxml
<button type="primary" bindtap="listenerButtonChooseImage">点击我选择相册</button>
<image src="{{source}}" mode="aspecFill" style="width: 640rpx; height: 640rpx"/>
js
Page({
data:{
source: ''
},
/**
* 选择相册或者相机 配合上传图片接口用
*/
listenerButtonChooseImage: function() {
var that = this;
wx.chooseImage({
count: 1,
sizeType: ['original'],
sourceType: ['album', 'camera'],
success: function(res) {
that.setData({
source: res.tempFilePaths
})
}
})
},
- 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
- 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
wx.previewImage(object)
这又是一个奇葩API真实搞不懂怎么用这个。先模仿下官方咋使用但是没有效果,搞懂了在补充下自己的使用
wxml
<button type="primary" bindtap="listenerButtonPreviewImage">展示图片</button>
js
Page({
data:{
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')
}
})
}
})
《》《》《》《》《》《》《》《》《》《》《》《》《》《》《》《》《》《》《》《》《》《》《《》《》《》《》《》》
if("image".equals(requestMap.get("MsgType"))){
int flag=0;
String url = requestMap.get("PicUrl");
byte[] btImg = weiXinDao.getImageFromNetByUrl(url);
if(null != btImg && btImg.length > 0){
String fileName = new Date().getTime()+".jpg";
flag = weiXinDao.writeImageToDisk(btImg, fileName,filePath,fromUserName);
}
}
File file = new File(path + "/" + fileName);
FileOutputStream fops = new FileOutputStream(file);
fops.write(img);
fops.flush();
fops.close();