|
|
|
|
|
|
|
|
@touchstart="handleTouchStart" @touchmove="handleTouchMove" @touchend="handleTouchEnd" |
|
|
@touchstart="handleTouchStart" @touchmove="handleTouchMove" @touchend="handleTouchEnd" |
|
|
:style="{ transform: `translate(${offsetX}px, ${offsetY}px) rotate(${rotateDegree}deg) scale(${scale})`, transition: 'transform ' + transitionDuration + 's' }"> |
|
|
:style="{ transform: `translate(${offsetX}px, ${offsetY}px) rotate(${rotateDegree}deg) scale(${scale})`, transition: 'transform ' + transitionDuration + 's' }"> |
|
|
</image> --> |
|
|
</image> --> |
|
|
<canvas canvas-id="canvasId" id="canvasId" style="height: 98vh;width: 100vh;" @touchstart="handleTouchStart" |
|
|
|
|
|
|
|
|
<canvas canvas-id="canvasId" id="canvasId" style="height: 100vh;width: 100vh;" @touchstart="handleTouchStart" |
|
|
@touchmove="handleTouchMove" @touchend="handleTouchEnd" |
|
|
@touchmove="handleTouchMove" @touchend="handleTouchEnd" |
|
|
:style="{ transform: `translate(${offsetX}px, ${offsetY}px) rotate(${rotateDegree}deg) scale(${scale})`, transition: 'transform ' + transitionDuration + 's' }"></canvas> |
|
|
:style="{ transform: `translate(${offsetX}px, ${offsetY}px) rotate(${rotateDegree}deg) scale(${scale})`, transition: 'transform ' + transitionDuration + 's' }"></canvas> |
|
|
</view> |
|
|
</view> |
|
|
|
|
|
|
|
|
query.select('.container').boundingClientRect((rect : any) => { |
|
|
query.select('.container').boundingClientRect((rect : any) => { |
|
|
if (rect) { |
|
|
if (rect) { |
|
|
|
|
|
|
|
|
// 获取图片信息 |
|
|
|
|
|
uni.getImageInfo({ |
|
|
|
|
|
src: src, |
|
|
|
|
|
success: (imgS) => { |
|
|
|
|
|
console.log('输出内容', imgS.width, imgS.height) |
|
|
|
|
|
// canvas.drawImage(img, 起始 x 坐标, 起始 y 坐标, 宽度, 高度, 绘制到 Canvas 的起始 x 坐标, 绘制到 Canvas 的起始 y 坐标, 裁剪后的宽度, 裁剪后的高度); |
|
|
|
|
|
context.drawImage(src, rect.left + 30, rect.top + 140, rect.width * 1.8, rect.height * 1.8, rect.left, rect.top, rect.width, rect.height); |
|
|
|
|
|
context.draw(false, () => { |
|
|
|
|
|
uni.canvasToTempFilePath({ |
|
|
|
|
|
canvasId: canvasId, |
|
|
|
|
|
x: rect.left, |
|
|
|
|
|
y: rect.top, |
|
|
|
|
|
width: rect.width, |
|
|
|
|
|
height: rect.height, |
|
|
|
|
|
destWidth: rect.width, |
|
|
|
|
|
destHeight: rect.height, |
|
|
|
|
|
success(res : any) { |
|
|
|
|
|
// res.tempFilePath 是转换后的图片路径 |
|
|
|
|
|
console.log(res.tempFilePath); |
|
|
|
|
|
res.tempImagePath = res.tempFilePath |
|
|
|
|
|
emit('confirmReturn', res) |
|
|
|
|
|
}, |
|
|
|
|
|
fail(err) { |
|
|
|
|
|
console.error('canvasToTempFilePath failed', err); |
|
|
|
|
|
} |
|
|
|
|
|
}, currentInstance.value) |
|
|
|
|
|
|
|
|
uni.getSystemInfo({ |
|
|
|
|
|
success: (demos) => { |
|
|
|
|
|
// 获取图片信息 |
|
|
|
|
|
uni.getImageInfo({ |
|
|
|
|
|
src: src, |
|
|
|
|
|
success: (imgS) => { |
|
|
|
|
|
//rect.top + + 200 demos.windowHeight * 0.7 + + demos.statusBarHeight |
|
|
|
|
|
console.log('输出内容', imgS.width, imgS.height, demos.windowWidth, demos.windowHeight, demos.statusBarHeight) ///180 |
|
|
|
|
|
// canvas.drawImage(img, 起始 x 坐标, 起始 y 坐标, 宽度, 高度, 绘制到 Canvas 的起始 x 坐标, 绘制到 Canvas 的起始 y 坐标, 裁剪后的宽度, 裁剪后的高度); |
|
|
|
|
|
context.drawImage(src, rect.left + 30, imgS.height * 0.21, rect.width * 1.8, rect.height * 1.8, rect.left, rect.top, rect.width, rect.height); |
|
|
|
|
|
context.draw(false, () => { |
|
|
|
|
|
uni.canvasToTempFilePath({ |
|
|
|
|
|
canvasId: canvasId, |
|
|
|
|
|
x: rect.left, |
|
|
|
|
|
y: rect.top, |
|
|
|
|
|
width: rect.width, |
|
|
|
|
|
height: rect.height, |
|
|
|
|
|
destWidth: rect.width, |
|
|
|
|
|
destHeight: rect.height, |
|
|
|
|
|
success(res : any) { |
|
|
|
|
|
// res.tempFilePath 是转换后的图片路径 |
|
|
|
|
|
console.log(res.tempFilePath); |
|
|
|
|
|
res.tempImagePath = res.tempFilePath |
|
|
|
|
|
emit('confirmReturn', res) |
|
|
|
|
|
}, |
|
|
|
|
|
fail(err) { |
|
|
|
|
|
console.error('canvasToTempFilePath failed', err); |
|
|
|
|
|
} |
|
|
|
|
|
}, currentInstance.value) |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
fail: (error) => { |
|
|
|
|
|
console.error('获取图片信息失败', error); |
|
|
|
|
|
}, |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
|
|
|
fail: (error) => { |
|
|
|
|
|
console.error('获取图片信息失败', error); |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//把当前画布指定区域的内容导出生成指定大小的图片,并返回文件路径。在自定义组件下,第二个参数传入自定义组件实例,以操作组件内 <canvas> 组件。 |
|
|
//把当前画布指定区域的内容导出生成指定大小的图片,并返回文件路径。在自定义组件下,第二个参数传入自定义组件实例,以操作组件内 <canvas> 组件。 |
|
|
|
|
|
|
|
|
top: 180px; |
|
|
top: 180px; |
|
|
left: 40px; |
|
|
left: 40px; |
|
|
width: 80%; |
|
|
width: 80%; |
|
|
height: 400rpx; |
|
|
|
|
|
|
|
|
height: 200px; |
|
|
border: 2px solid #fff; |
|
|
border: 2px solid #fff; |
|
|
box-sizing: border-box; |
|
|
box-sizing: border-box; |
|
|
border-radius: 16rpx; |
|
|
border-radius: 16rpx; |