Home WeChat Applet Mini Program Development WeChat Mini Program Image API Example Detailed Explanation

WeChat Mini Program Image API Example Detailed Explanation

Feb 14, 2017 pm 02:11 PM

This article mainly introduces relevant information about the detailed explanation of the WeChat applet Image API instance. Friends in need can refer to it

微信小程序 Image API实例详解

When selecting a picture, you can set whether the picture is the original Figure, image source. This is also quite common. For example, to set an avatar in the personal center, you can use it with wx.upLoadFile() API

Main method:

wx.chooseImage(object )

微信小程序 Image API实例详解

##wxml

<!--监听按钮-->
<button type="primary" bindtap="listenerButtonChooseImage">点击我选择相册</button>
<!--通过数据绑定的方式动态获取js数据-->
<image src="{{source}}" mode="aspecFill" style="width: 640rpx; height: 640rpx"/>
Copy after login

js

Page({
 data:{
  // text:"这是一个页面"
  source: &#39;&#39;
 },
 /**
  * 选择相册或者相机 配合上传图片接口用
  */
 listenerButtonChooseImage: function() {
   var that = this;
   wx.chooseImage({
     count: 1,
     //original原图,compressed压缩图
     sizeType: [&#39;original&#39;],
     //album来源相册 camera相机 
     sourceType: [&#39;album&#39;, &#39;camera&#39;],
     //成功时会回调
     success: function(res) {
       //重绘视图
       that.setData({
         source: res.tempFilePaths
       })
     }
   })
 },
Copy after login

wx.previewImage(object)

微信小程序 Image API实例详解

This is another weird API. I really don’t understand why. use this. I first imitated the official use but it had no effect. After I figured it out, I supplemented my own use

wxml

<!--图片预览-->
<button type="primary" bindtap="listenerButtonPreviewImage">展示图片</button>
Copy after login

js

Page({
 data:{
  // text:"这是一个页面"
  source: &#39;&#39;
 },

 /**
  * 预览图片 又一个奇葩接口
  */
 listenerButtonPreviewImage: function() {
   wx.previewImage({
     current: &#39;http://img.souutu.com/2016/0511/20160511055648316.jpg&#39;,
     urls: [
       &#39;http://img.souutu.com/2016/0511/20160511055648316.jpg&#39;,
        &#39;http://img.souutu.com/2016/0511/20160511055650751.jpg&#39;,
        &#39;http://img.souutu.com/2016/0511/20160511054928658.jpg&#39;
        ],
        //这根本就不走
        success: function(res) {
          console.log(res);
        },
        //也根本不走
        fail: function() {
          console.log(&#39;fail&#39;)
        }
   })
 }


})
Copy after login

Thank you for reading this article, I hope it can help everyone, thank you for your support of this site!

For more detailed explanations of WeChat applet Image API examples and related articles, please pay attention to the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)