93 lines
2.2 KiB
Vue
93 lines
2.2 KiB
Vue
<template>
|
|
<view>
|
|
|
|
<canvas canvas-id="splashCanvas"
|
|
style="width: 160px; height: 80px; z-index: 9999;position: fixed; visibility: visible;top: 0px;left:0px;"
|
|
|
|
</canvas>
|
|
|
|
<qf-image-cropper :src="src" :showAngle="false" :width="1600" :height="800" fileType="jpg"
|
|
@crop="handleCrop" :gpu="true">
|
|
</qf-image-cropper>
|
|
|
|
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import QfImageCropper from '@/uni_modules/qf-image-cropper/components/qf-image-cropper/qf-image-cropper.vue';
|
|
export default {
|
|
components: {
|
|
QfImageCropper
|
|
},
|
|
data() {
|
|
return {
|
|
src:"",
|
|
Statu: false
|
|
|
|
}
|
|
},
|
|
onLoad:function(option){
|
|
const eventChannel = this.getOpenerEventChannel();
|
|
var these=this;
|
|
eventChannel.on('checkImg', function(data) {
|
|
console.log("我收到你的消息了,消息内容是:"+JSON.stringify(data));
|
|
these.src=data.data;
|
|
})
|
|
},
|
|
methods: {
|
|
handleCrop(e) {
|
|
var these=this;
|
|
this.Statu = true;
|
|
console.log("裁剪完成");
|
|
console.log(e.tempFilePath);
|
|
|
|
|
|
const ctx = uni.createCanvasContext('splashCanvas', these);
|
|
console.log("1111111");
|
|
// 绘制图片到canvas
|
|
ctx.drawImage(e.tempFilePath, 0, 0, 160, 80);
|
|
console.log("22222");
|
|
ctx.draw(false, () => {
|
|
// 获取canvas像素数据
|
|
console.log("444444");
|
|
setTimeout(() => {
|
|
uni.canvasGetImageData({
|
|
canvasId: 'splashCanvas',
|
|
x: 0,
|
|
y: 0,
|
|
width: 160,
|
|
height: 80,
|
|
success: (res) => {
|
|
// 处理像素数据并发送
|
|
console.log("res.data.length="+res.data.length);
|
|
// this.processAndSendImageData(res.data).then(
|
|
// resolve).catch(reject);
|
|
const eventChannel = these.getOpenerEventChannel();
|
|
eventChannel.emit('ImgCutOver',res.data);
|
|
uni.navigateBack();
|
|
},
|
|
fail: (err) => {
|
|
reject(`获取canvas数据失败: ${err.errMsg}`);
|
|
}
|
|
});
|
|
}, 500); // 等待canvas绘制完成
|
|
});
|
|
|
|
console.log("333333");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.canvas {
|
|
width: 1600px;
|
|
height: 800px;
|
|
border: 1px solid #ccc;
|
|
}
|
|
</style> |