my.previewImage

The Preview image's "local image path" is not supported.

Note: On the iOS, the basic library version is 1.0.0 and it does not support the combined use of my.previewImage and my.chooseImage.

Sample Code

copy
    // API-DEMO page/API/image/image.json
    {
        "defaultTitle": "Picture"
    }
copy
    <!-- API-DEMO page/API/image/image.axml -->
    <view class="page">
      <view class="page-section">
        <view class="page-section-btns">
          <view onTap="chooseImage">Select image</view>
          <view onTap="previewImage">Preview image</view>
          <view onTap="saveImage">Save image</view>
        </view>
      </view>
    </view>
copy
    // API-DEMO page/API/image/image.js
    Page({
      chooseImage() {
        my.chooseImage({
          sourceType: ['camera','album'],
          count: 2,
          success: (res) => {
            my.alert({
              content: JSON.stringify(res),
              
            });
          },
          fail:()=>{
            my.showToast({
              content: 'fail', // text contents 
            });
          }
        })
      },
      previewImage() {
        my.previewImage({
          current: 2,
          urls: [
            'https://img.example.com/example1.jpg',
            'https://img.example.com/example2.jpg',
            'https://img.example.com/example3.jpg'
          ],
        });
      },
      saveImage() {
        my.saveImage({
          url: 'https://img.example.com/example1.jpg',
          showActionSheet: true,
          success: () => {
            my.alert({
              title: 'Save success',
            });
          },
        });
      }
    });

Parameters

The incoming parameter is of the Object type with the following attributes:

AttributesTypeDefault MandatoryDescription
urlsArrayYeshttp url list of the images to be previewed
currentNumber0Index of the current displayed image, 0 by default, indicating the first image in the URLs
successFunctionNoCallback function for call success
failFunctionNoCallback function for call failure
completeFunctionNoCallback function for call completion (to be executed for both call success and failure)