This article shares the specific code for WeChat applet to realize taking photos and selecting pictures from albums for your reference. The specific content is as follows layout: <!--pages/camera/camera.wxml--> <view class="tui-menu-list" id="view1" style="display:flex;flex-direction:space-between"> <button id="b1" size="mini" type="primary" bindtap="chooseimage"> Get image</button> <button id="b2" size="mini" type="primary" bindtap="savePhone"> Save</button> </view> <image src="{{tempFilePaths}}" catchtap="chooseImageTap" mode="aspectFit" style="width:100%;height:400px;background-color:#ffffff;"> </image> style: /* pages/camera/camera.wxss */ .view1 { height: 25px } .tui-menu-list { display: flex; flex-direction: row; margin: 20rpx; padding: 20rpx; } Get the image path, display the image and save it // pages/camera/camera.js Page({ data: { tempFilePaths: 'http://pic2.cxtuku.com/00/01/08/b207004f7104.jpg' }, chooseimage: function () { var that = this; wx.showActionSheet({ itemList: ['Select from album', 'Take photo'], itemColor: "#CED63A", success: function (res) { if (!res.cancel) { if (res.tapIndex == 0) { that.chooseWxImage('album') } else if (res.tapIndex == 1) { that.chooseWxImage('camera') } } } }) }, chooseWxImage: function (type) { var that = this wx.chooseImage({ sizeType: ['original', 'compressed'], sourceType: [type], count: 1, success: function (res) { console.log(res) that.setData({ tempFilePaths: res.tempFilePaths[0], }) } }) }, savePhone: function () { wx.getImageInfo({ src: this.data.tempFilePaths, success: function (res) { var path = res.path wx.saveImageToPhotosAlbum({ filePath: path, success: function () { wx.showToast({ title: 'Save successfully', }) }, fail: function (res) { wx.showToast({ title: 'Save failed', icon: 'none' }) } }) } }) } }) Effect picture: The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to customize at and cron scheduled tasks in Linux
>>: Detailed explanation of outfile, dumpfile, load_file functions in MySQL injection
Table of contents Preface 1. Technical Principle ...
Copy code The code is as follows: <style type=...
Table of contents definition Constructor bodies a...
This work uses the knowledge of front-end develop...
Scenario: When page A opens page B, after operati...
To back up multiple databases, you can use the fo...
1. Edit the PAM configuration file sudo vim /etc/...
Table of contents 1. Environmental Preparation 1....
This article shares with you how to use JavaScrip...
Will UPDATE lock? Will the SQL statement be locke...
Table of contents Overview Implementation Protect...
Table of contents 1. Introduction 2. Main text 2....
You can use the ps command. It can display releva...
Find the problem After upgrading MySQL to MySQL 5...
The project requirements are: select date and tim...