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
Install MySQL and keep a note. I don’t know if it...
1. Set firewall rules Example 1: Expose port 8080...
Preface For file or directory permissions in Linu...
The previous article wrote about how to manually ...
Table of contents 1. Basics 2. Nodes, trees, and ...
Table of contents 1. Original value and reference...
1. Preparation 1.1 Download and install VMware 15...
The local environment is Windows 10 + WSL2 (Ubunt...
Table of contents 1. Front-end routing implementa...
The default arrangement of text in HTML is horizo...
1. Overflow Overflow is overflow (container). Whe...
View the IP address of the Container docker inspe...
1. Zabbix backup [root@iZ2zeapnvuohe8p14289u6Z /]...
This situation usually occurs because the Chinese...
Overview I have recently started learning MySQL r...