cutawayCanvasFn(_this) {
let that = this;
console.log(`createCanvasContext image-canvas`)
const ctx = wx.createCanvasContext("image-canvas",that);
console.log('ctx',ctx)
// that.canvas = uni.createCanvasContext("image-canvas", that);
// 获取屏幕的宽高,对图片进行剪裁准备
wx.getSystemInfo({
success(res) {
console.log('获取屏幕的宽高',res)
let windowWidth = res.windowWidth;
let windowHeight = res.windowHeight;
that.windowWidth = windowWidth;
that.windowHeight = windowHeight;
wx.getImageInfo({
src: that.ocrImgUrl,
success(res) {
console.log('获取图片信息',res)
//过渡页面中,图片的路径坐标和大小
ctx.drawImage(that.ocrImgUrl,0,0,windowWidth,windowHeight);
let newX = (windowWidth - 335) / 2;
let newY = windowHeight / 2 - 129;
let newWidth = 335;
let newHeight = 129;
// ctx.setStrokeStyle("red"); // 描边
ctx.strokeRect(newX, newY, newWidth, newHeight); // 裁切
ctx.restore()
ctx.draw(false, function(res){
console.log(`that.canvas.draw sueccess`,res)
});
setTimeout(() => {
wx.hideLoading()
console.log('剪裁开始',_this,that,that.canvas)
wx.canvasToTempFilePath({
//裁剪对参数
x: newX, //画布x轴起点
y: newY, //画布y轴起点
width: newWidth, //画布宽度
height: newHeight, //画布高度
destWidth: newWidth, //输出图片宽度
destHeight: newHeight, //输出图片高度
canvasId: "image-canvas",
success(res) {
that.filePath = res.tempFilePath;
that.newImageSrc = res.tempFilePath;
//清除画布上在该矩形区域内的内容。
that.canvas.clearRect(0, 0, windowWidth, windowHeight);
that.canvas.drawImage(
that.filePath,
newX,
newY,
newWidth,
newHeight
);
that.canvas.draw();
//在此可进行网络请求
// that.SaveVehicleImage(that.newImageSrc);
},
fail(e) {
console.log(e)
wx.hideLoading();
wx.showToast({
title: "出错啦...",
icon: "loading"
});
}
},that);
}, 5000);
}
});
}
});
},
that上有这个方法? 不应该是ctx.