Home > WeChat Applet > Mini Program Development > About chooseImage in WeChat applet to select pictures or take pictures

About chooseImage in WeChat applet to select pictures or take pictures

不言
Release: 2018-06-26 17:37:05
Original
4187 people have browsed it

This article mainly introduces the relevant information about selecting pictures or taking photos in the WeChat applet chooseImage. Friends who need it can refer to

WeChat applet chooseImage selects pictures or takes photos

1. Use API wx.chooseImage(OBJECT)

var util = require('../../utils/util.js')
Page({
  data:{
    src:"../image/pic4.jpg"
  },
  gotoShow: function(){var _this = this
    wx.chooseImage({
     count: 9, // 最多可以选择的图片张数,默认9
     sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
     sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
     success: function(res){
      // success
      console.log(res)
      _this.setData({
        src:res.tempFilePaths
      })
     },
     fail: function() {
      // fail
     },
     complete: function() {
      // complete
     }
    })
  }
Copy after login

2. Image path for data binding

<view class="container">
 <view>
  <button type="default" bindtap="gotoShow" >点击上传照片</button> 
 </view>
 <view>
  <image class= "show-image" mode="aspectFitf" src="{{src}}"></image>
 </view>
</view>
Copy after login

Exception:

1. wx.chooseImage calls the camera or album
2. Data binding
 3. Dynamically modify the file path in js

 var _this = this
    wx.chooseImage({
     count: 9, // 最多可以选择的图片张数,默认9
     sizeType: [&#39;original&#39;, &#39;compressed&#39;], // original 原图,compressed 压缩图,默认二者都有
     sourceType: [&#39;album&#39;, &#39;camera&#39;], // album 从相册选图,camera 使用相机,默认二者都有
     success: function(res){
      // success
      console.log(res)
      _this.setData({
        src:res.tempFilePaths
      })
     },
     fail: function() {
      // fail
     },
     complete: function() {
      // complete
     }
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About the code for uploading avatars in WeChat mini programs

About the animation effects of WeChat mini programs Implementation

Introduction to album selection and photo taking in the WeChat applet

The above is the detailed content of About chooseImage in WeChat applet to select pictures or take pictures. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template