原生小程序使用we-cropper实现照片裁剪
<import src="../we-cropper/we-cropper.wxml" /> <-- 引入 -->
<template is="we-cropper" data="{{...cropperOpt}}" />
<view class="cropperbg">
<template is="we-cropper" data="{{...cropperOpt}}" />
<view class="flex-wrap rowcenter mgt-15">
<view class="operation_icon">
<image src="/package/image/icon_cancel.png" bindtap="cancel_sel" />
<image src="/package/image/icon_camera.png" bindtap="getCropperImage" />
</view>
<!-- <van-button
type="info"
bindtap="chooseimg"
size="large"
custom-style="width:90vw;border-radius:20rpx;height:80rpx"
>选择图片
</van-button>
<van-button
type="info"
bindtap="getCropperImage"
size="large"
custom-style="width:90vw;border-radius:20rpx;height:80rpx"
>保存
</van-button> -->
</view>
</view>
import WeCropper from '../we-cropper/we-cropper'
const device = wx.getSystemInfoSync() // 获取设备信息
const width = device.windowWidth // 示例为一个与屏幕等宽的正方形裁剪框
const height = width
onLoad(option) {
const { cropperOpt } = this.data
this.cropper = new WeCropper(cropperOpt)
.on('ready', (ctx) => {
console.log(`wecropper is ready for work!`)
})
.on('beforeImageLoad', (ctx) => {
wx.showToast({
title: '上传中',
icon: 'loading',
duration: 20000,
})
})
.on('imageLoad', (ctx) => {
wx.hideToast()
})
},
touchStart(e) {
this.cropper.touchStart(e)
},
touchMove(e) {
this.cropper.touchMove(e)
},
touchEnd(e) {
this.cropper.touchEnd(e)
},
// 选择
selImg() {
let that = this
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success(res) {
const tempFilePaths = res.tempFilePaths[0]
that.cropper.pushOrign(tempFilePaths)
},
})
},
data:{
cropperOpt: {
id: 'cropper', // 用于手势操作的canvas组件标识符
targetId: 'targetCropper', // 用于用于生成截图的canvas组件标识符
pixelRatio: device.pixelRatio, // 传入设备像素比
width, // 画布宽度
height, // 画布高度
scale: 2.5, // 最大缩放倍数
zoom: 8, // 缩放系数
cut: {
x: (width - 200) / 2, // 裁剪框x轴起点
y: (width - 200) / 2, // 裁剪框y轴期起点
width: 200, // 裁剪框宽度
height: 200, // 裁剪框高度
},
},
}
本文来自博客园,作者:小万子呀,转载请注明原文链接:https://www.cnblogs.com/newBugs/p/17128921.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
2022-02-17 uniapp自定义导航栏navbar
2022-02-17 uniapp自定义tabbar