Detailed explanation of the code for selecting and taking photos of WeChat mini-app development albums

Source: Internet
Author: User
This article mainly describes the selection of photo albums for mini-program development and the relevant information of the instance code. For more information, see the following article, for more information, see

Mini-app photo and camera selection details

Preface:

You can get an image in a applet in two ways. The first is to directly open your own style, the first is to take a photo of the camera, followed by an image, the second method is to prompt the user whether to take a photo or choose from the album in the pop-up box. let's take a look at it one by one below.

The wx. chooseImage (OBJECT) function is used to select an album. the specific parameters are as follows:

Page ({data: {tempFilePaths: ''}, onLoad: function () {}, chooseimage: function () {var that = this; wx. chooseImage ({count: 1, // Default 9 sizeType: ['original', 'compressed '], // you can specify whether the source image or the compressed image is used. Both have sourceType by default: ['alipay', 'Camera '], // you can specify whether the source is an album or a camera. Both have success: function (res) by default) {// return the local file path list of the selected photo. the tempFilePath can be used as the src attribute of the img label to display the image that. setData ({tempFilePaths: res. tempFilePaths })}})},})

Method 1:

Page ({data: {tempFilePaths: ''}, onLoad: function () {}, chooseimage: function () {var that = this; wx. showActionSheet ({itemList: ['Select from album ', 'photographed'], itemColor: "# CED63A", success: function (res) {if (! Res. cancel) {if (res. tapIndex = 0) {that. chooseWxImage ('alipay')} else if (res. tapIndex = 1) {that. chooseWxImage ('cama') }}}, chooseWxImage: function (type) {var that = this; wx. chooseImage ({sizeType: ['original', 'computed'], sourceType: [type], success: function (res) {console. log (res); that. setData ({tempFilePaths: res. tempFilePaths [0],}) }}})

The temporary path of the file, which can be used normally during the startup of the applet. to save the file permanently, you must call wx. saveFile to access the file at the next startup of the applet.

Layout file:


Get image

The above is a detailed description of the code for selecting and taking photos of the album for mini-program development. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.