|
@@ -55,6 +55,7 @@ Page({
|
|
},
|
|
},
|
|
src: '',
|
|
src: '',
|
|
showProgress: false,
|
|
showProgress: false,
|
|
|
|
+ showCropImg: false,
|
|
width: 250,//宽度
|
|
width: 250,//宽度
|
|
height: 250,//高度
|
|
height: 250,//高度
|
|
_imageBuffer: null,
|
|
_imageBuffer: null,
|
|
@@ -95,7 +96,7 @@ Page({
|
|
src: res.path,// 图片路径
|
|
src: res.path,// 图片路径
|
|
cropScale: '1:1', // 裁剪比例
|
|
cropScale: '1:1', // 裁剪比例
|
|
success(res) {
|
|
success(res) {
|
|
- console.log(res)
|
|
|
|
|
|
+ console.log("裁剪后的图片", res)
|
|
that.convertImageToRGB565(res.tempFilePath)
|
|
that.convertImageToRGB565(res.tempFilePath)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -110,37 +111,46 @@ Page({
|
|
// 将图片转换为 RGB565
|
|
// 将图片转换为 RGB565
|
|
convertImageToRGB565(imagePath) {
|
|
convertImageToRGB565(imagePath) {
|
|
const ctx = wx.createCanvasContext('imageCanvas');
|
|
const ctx = wx.createCanvasContext('imageCanvas');
|
|
|
|
+ // const ctx = Canvas.getContext('imageCanvas');
|
|
let _this = this;
|
|
let _this = this;
|
|
- wx.getImageInfo({
|
|
|
|
- src: imagePath,
|
|
|
|
- success: (info) => {
|
|
|
|
- const { width, height } = info;
|
|
|
|
-
|
|
|
|
- // 设置 Canvas 尺寸
|
|
|
|
- _this.setData({ canvasWidth: width, canvasHeight: height });
|
|
|
|
-
|
|
|
|
- // 在 Canvas 中绘制图片
|
|
|
|
- ctx.drawImage(imagePath, 0, 0, width, height);
|
|
|
|
- ctx.draw(false, () => {
|
|
|
|
- // 获取图片像素数据
|
|
|
|
- wx.canvasGetImageData({
|
|
|
|
- canvasId: 'imageCanvas',
|
|
|
|
- x: 0,
|
|
|
|
- y: 0,
|
|
|
|
- width,
|
|
|
|
- height,
|
|
|
|
- success: (res) => {
|
|
|
|
|
|
+ let width = 400;
|
|
|
|
+ let height = 400;
|
|
|
|
+ try {
|
|
|
|
+ // 设置 Canvas 尺寸
|
|
|
|
+ // _this.setData({ canvasWidth: width, canvasHeight: height });
|
|
|
|
+
|
|
|
|
+ // 在 Canvas 中绘制图片
|
|
|
|
+ ctx.drawImage(imagePath, 0, 0, width, height);
|
|
|
|
+ ctx.draw(false, () => {
|
|
|
|
+ // 获取图片像素数据
|
|
|
|
+ wx.canvasGetImageData({
|
|
|
|
+ canvasId: 'imageCanvas',
|
|
|
|
+ x: 0,
|
|
|
|
+ y: 0,
|
|
|
|
+ width,
|
|
|
|
+ height,
|
|
|
|
+ success: (res) => {
|
|
|
|
+ console.log('获取像素数据成功:', res.data);
|
|
|
|
+ if (res.data) {
|
|
|
|
+ _this.setData({
|
|
|
|
+ showCropImg: true,
|
|
|
|
+ topImg: { "pic": imagePath }
|
|
|
|
+ })
|
|
const rgb565Data = _this.RGBAtoRGB565(res.data);
|
|
const rgb565Data = _this.RGBAtoRGB565(res.data);
|
|
_this.data.imageBuffer = rgb565Data;
|
|
_this.data.imageBuffer = rgb565Data;
|
|
- // this.saveAsBinFile(rgb565Data, width, height);
|
|
|
|
- },
|
|
|
|
- fail: (err) => {
|
|
|
|
- console.error('获取像素数据失败:', err);
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // this.saveAsBinFile(rgb565Data, width, height);
|
|
|
|
+ },
|
|
|
|
+ fail: (err) => {
|
|
|
|
+ console.error('获取像素数据失败:', err);
|
|
|
|
+ },
|
|
});
|
|
});
|
|
- },
|
|
|
|
- });
|
|
|
|
|
|
+ });
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+
|
|
},
|
|
},
|
|
|
|
|
|
// 将 RGBA 数据转换为 RGB565 格式
|
|
// 将 RGBA 数据转换为 RGB565 格式
|
|
@@ -265,6 +275,7 @@ Page({
|
|
progress: 0,
|
|
progress: 0,
|
|
progressPercent: 0,
|
|
progressPercent: 0,
|
|
showProgress: false,
|
|
showProgress: false,
|
|
|
|
+ showCropImg: false
|
|
});
|
|
});
|
|
wx.showToast({
|
|
wx.showToast({
|
|
title: '图片上传成功',
|
|
title: '图片上传成功',
|