微信小程序截圖工具 - 新聞資訊 - 雲南小程序開發|雲南軟件開發|雲南網站建設-昆明融晨信息技術有限公司

159-8711-8523

雲南網建設/小程序開發/軟件開發

知識

不(bù)管是(shì)網站,軟件還是(shì)小程序,都要(yào / yāo)直接或間接能爲(wéi / wèi)您産生價值,我們在(zài)追求其視覺表現的(de)同時(shí),更側重于(yú)功能的(de)便捷,營銷的(de)便利,運營的(de)高效,讓網站成爲(wéi / wèi)營銷工具,讓軟件能切實提升企業内部管理水平和(hé / huò)效率。優秀的(de)程序爲(wéi / wèi)後期升級提供便捷的(de)支持!

您當前位置>首頁 » 新聞資訊 » 小程序相關 >

微信小程序截圖工具

發表時(shí)間:2021-4-22

發布人(rén):融晨科技

浏覽次數:101

welCropper 微信小程序截圖工具

文件目錄結構,要(yào / yāo)在(zài)測試機上(shàng)運行,工程目錄選擇文件夾project

./
├── documents
│   ├── hierarchy.png
│   ├── result.gif
│   └── screenshot.jpeg
├── project
│   ├── app.js
│   ├── app.json
│   ├── app.wxss
│   ├── pages
│   │   ├── index
│   │   │   ├── index.js
│   │   │   ├── index.json
│   │   │   ├── index.wxml
│   │   │   └── index.wxss
│   │   └── test
│   │       ├── test.js
│   │       ├── test.json
│   │       ├── test.wxml
│   │       └── test.wxss
│   ├── utils
│   │   └── util.js
│   └── welCropper
│       ├── welCropper.js
│       ├── welCropper.wxml
│       └── welCropper.wxss
└── readme.md
  • 保證圖片質量,也(yě)可以(yǐ)選擇壓縮圖

Documents

因爲(wéi / wèi)cropper的(de)數據和(hé / huò)事件是(shì)直接綁定到(dào)Page上(shàng)的(de),所以(yǐ)數據和(hé / huò)事件命名應該避免一下名字(之(zhī)後會想辦法避免這(zhè)種情況)及其相關解釋:

data中的(de)名字:

  • cropperData
  • cropperMovableItems

函數名:

  • showCropper
  • hideCropper
  • originalChange
  • cropImage
  • loadImage
  • clearCanvas
  • drawImage
  • drawOriginalImage
  • drawLines
  • setupMoveItem
  • moveEvent
  • endEvent

外部隻用到(dào)showCropper和(hé / huò)hideCropper

/**
    inputPath:輸入圖片地(dì / de)址
    callback(resPath):點擊“完成”按鈕後毀掉函數,毀掉函數中會有截圖地(dì / de)址
*/
showCropper(inputPath, callback)

使用

welCropper複制到(dào)自己的(de)工程當中(以(yǐ)/pages/index/index爲(wéi / wèi)例)

wxml引入并調用:
<!-- 引入組件 -->
<import src="https://www.wxapp-union.com/welCropper/welCropper" />

<!-- 調用組件 -->
<template is="welCropper" data="{{data:cropperData, cropperMovableItems:cropperMovableItems}}"></template>

<!-- 用于(yú)選擇圖片,傳入cropper中 -->
<button bindtap='selectTap'>select image</button>
wxss引入:
@import "/welCropper/welCropper.wxss";
js引入和(hé / huò)使用:
// 獲取顯示區域長寬
const device = wx.getSystemInfoSync()
const W = device.windowWidth
const H = device.windowHeight - 50

let cropper = require('../../welCropper/welCropper.js');

console.log(device)

Page({
    data: {
    },
    onLoad: function () {
        var that = this
        // 初始化組件數據和(hé / huò)綁定事件
        cropper.init.apply(that, [W, H]);
    },
    selectTap() {
        var that = this

        wx.chooseImage({
            count: 1, // 默認9
            sizeType: ['original', 'compressed'], // 可以(yǐ)指定是(shì)原圖還是(shì)壓縮圖,默認二者都有
            sourceType: ['album', 'camera'], // 可以(yǐ)指定來(lái)源是(shì)相冊還是(shì)相機,默認二者都有
            success(res) {
                const tempFilePath = res.tempFilePaths[0]
                console.log(tempFilePath)

                // 将選取圖片傳入cropper,并顯示cropper
                that.showCropper({
                    src: tempFilePath,
                    sizeType: ['original', 'compressed'],   //'original' | 'compressed'(default)
                    callback: (resPath) => {
                        console.log("crop callback:" + resPath)
                        wx.previewImage({
                            current: '',
                            urls: [resPath]
                        })

                        // that.hideCropper() //隐藏,我在(zài)項目裏是(shì)點擊完成就(jiù)上(shàng)傳,所以(yǐ)如果回調是(shì)上(shàng)傳,那麽隐藏掉就(jiù)行了(le/liǎo),不(bù)用previewImage
                    }
                })
            }
        })
    }

相關案例查看更多