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!