|
@@ -2,12 +2,8 @@
|
|
const { deviceWallPaper } = require('../../../request/deviceListRequest')
|
|
const { deviceWallPaper } = require('../../../request/deviceListRequest')
|
|
// const sharp = require('sharp');
|
|
// const sharp = require('sharp');
|
|
// const fs = require('fs');
|
|
// const fs = require('fs');
|
|
-const {
|
|
|
|
- BtHelper
|
|
|
|
-} = require('../../../devices/bt_helper');
|
|
|
|
-const { BtCmd } = require('../../../devices/bluetooth/bt_cmd');
|
|
|
|
-import EventManager from '../../../utils/event_bus'
|
|
|
|
-import { EnumCmdEvent, CmdEvent } from '../../../devices/cmd_key_event';
|
|
|
|
|
|
+
|
|
|
|
+import route_util from '../../../utils/route_util';
|
|
|
|
|
|
// import EventManager from '../../utils/event_bus'
|
|
// import EventManager from '../../utils/event_bus'
|
|
|
|
|
|
@@ -53,14 +49,8 @@ Page({
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- src: '',
|
|
|
|
- showProgress: false,
|
|
|
|
- showCropImg: true,
|
|
|
|
- width: 250,//宽度
|
|
|
|
- height: 250,//高度
|
|
|
|
- _imageBuffer: null,
|
|
|
|
- progressPercent: 0,
|
|
|
|
- _timer: null,
|
|
|
|
|
|
+ showCropImg: false,
|
|
|
|
+
|
|
|
|
|
|
},
|
|
},
|
|
closePage() {
|
|
closePage() {
|
|
@@ -68,6 +58,8 @@ Page({
|
|
|
|
|
|
},
|
|
},
|
|
footerTap() {
|
|
footerTap() {
|
|
|
|
+ route_util.jump("../cropper/cropper")
|
|
|
|
+ return;
|
|
const that = this;
|
|
const that = this;
|
|
|
|
|
|
wx.chooseMedia({
|
|
wx.chooseMedia({
|
|
@@ -76,125 +68,37 @@ Page({
|
|
sourceType: ['album'],
|
|
sourceType: ['album'],
|
|
// camera: 'back',
|
|
// camera: 'back',
|
|
success(res) {
|
|
success(res) {
|
|
- console.log(res.tempFiles[0].tempFilePath)
|
|
|
|
- console.log(res.tempFiles[0].size)
|
|
|
|
-
|
|
|
|
- // that.setData({
|
|
|
|
- // imageSrc: res.tempFiles[0].tempFilePath, // 图片路径
|
|
|
|
- // showCrop: true
|
|
|
|
|
|
+ // console.log(res.tempFiles[0].tempFilePath)
|
|
|
|
+ // console.log(res.tempFiles[0].size)
|
|
|
|
+ //重置图片角度、缩放、位置
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // wx.getImageInfo({
|
|
|
|
+ // src: res.tempFiles[0].tempFilePath,
|
|
|
|
+ // success(res) {
|
|
|
|
+ // console.log(res)
|
|
|
|
+ // wx.cropImage({
|
|
|
|
+ // src: res.path,// 图片路径
|
|
|
|
+ // cropScale: '1:1', // 裁剪比例
|
|
|
|
+ // success(res) {
|
|
|
|
+ // console.log("裁剪后的图片", res)
|
|
|
|
+ // that.setData({
|
|
|
|
+ // showCropImg: true,
|
|
|
|
+ // topImg: { "pic": res.tempFilePath }
|
|
|
|
+ // })
|
|
|
|
+ // that.convertImageToRGB565(res.tempFilePath)
|
|
|
|
+
|
|
|
|
+ // },
|
|
|
|
+
|
|
|
|
+ // })
|
|
|
|
+ // }
|
|
// })
|
|
// })
|
|
|
|
|
|
- // wx.editImage({
|
|
|
|
- // src: res.tempFiles[0].tempFilePath, // 图片路径
|
|
|
|
- // })
|
|
|
|
-
|
|
|
|
- wx.getImageInfo({
|
|
|
|
- src: res.tempFiles[0].tempFilePath,
|
|
|
|
- success(res) {
|
|
|
|
- console.log(res)
|
|
|
|
- wx.cropImage({
|
|
|
|
- src: res.path,// 图片路径
|
|
|
|
- cropScale: '1:1', // 裁剪比例
|
|
|
|
- success(res) {
|
|
|
|
- console.log("裁剪后的图片", res)
|
|
|
|
- that.setData({
|
|
|
|
- showCropImg: true,
|
|
|
|
- topImg: { "pic": res.tempFilePath }
|
|
|
|
- })
|
|
|
|
- that.convertImageToRGB565(res.tempFilePath)
|
|
|
|
-
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
- // 将图片转换为 RGB565
|
|
|
|
- convertImageToRGB565(imagePath) {
|
|
|
|
- const ctx = wx.createCanvasContext('imageCanvas');
|
|
|
|
- // const ctx = Canvas.getContext('imageCanvas');
|
|
|
|
- let _this = this;
|
|
|
|
- let width = 533;
|
|
|
|
- let height = 533;
|
|
|
|
- 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);
|
|
|
|
- _this.data.imageBuffer = rgb565Data;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // this.saveAsBinFile(rgb565Data, width, height);
|
|
|
|
- },
|
|
|
|
- fail: (err) => {
|
|
|
|
- console.error('获取像素数据失败:', err);
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
- } catch (error) {
|
|
|
|
- console.log(error)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- // 将 RGBA 数据转换为 RGB565 格式
|
|
|
|
- RGBAtoRGB565(data) {
|
|
|
|
- const rgb565Array = new Uint16Array(data.length / 4);
|
|
|
|
-
|
|
|
|
- for (let i = 0; i < data.length; i += 4) {
|
|
|
|
- const r = data[i];
|
|
|
|
- const g = data[i + 1];
|
|
|
|
- const b = data[i + 2];
|
|
|
|
- // 转换为 RGB565
|
|
|
|
- const rgb565 = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
|
|
|
|
- rgb565Array[i / 4] = rgb565;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return rgb565Array;
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- // 保存为 .bin 文件
|
|
|
|
- saveAsBinFile(data, width, height) {
|
|
|
|
- const arrayBuffer = data.buffer;
|
|
|
|
-
|
|
|
|
- wx.getFileSystemManager().writeFile({
|
|
|
|
- filePath: `${wx.env.USER_DATA_PATH}/image_rgb565_${width}x${height}.bin`,
|
|
|
|
- data: arrayBuffer,
|
|
|
|
- encoding: 'binary',
|
|
|
|
- success: () => {
|
|
|
|
- wx.showToast({
|
|
|
|
- title: '保存成功',
|
|
|
|
- icon: 'success',
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
- fail: (err) => {
|
|
|
|
- console.error('文件保存失败:', err);
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
imageTap(e) {
|
|
imageTap(e) {
|
|
// console.log(e)
|
|
// console.log(e)
|
|
// wxfile://tmp_d3e57489ead39c698676ff860df9cb8a37f66ee1a4777dbb.jpg
|
|
// wxfile://tmp_d3e57489ead39c698676ff860df9cb8a37f66ee1a4777dbb.jpg
|
|
@@ -230,71 +134,12 @@ Page({
|
|
}
|
|
}
|
|
|
|
|
|
this.setData({
|
|
this.setData({
|
|
- imageSrc: "",//要裁剪的图片
|
|
|
|
- showCrop: false
|
|
|
|
|
|
+ showCropImg: true,
|
|
|
|
+ topImg: { "pic": img.path }
|
|
})
|
|
})
|
|
|
|
|
|
},
|
|
},
|
|
- startImage() {
|
|
|
|
- BtHelper.sendData(BtCmd.wallPaper(1));
|
|
|
|
- },
|
|
|
|
- sendImage(imageBuffer) {
|
|
|
|
- if (imageBuffer == null) {
|
|
|
|
- wx.showToast({
|
|
|
|
- title: '图片裁剪失败',
|
|
|
|
- icon: 'none'
|
|
|
|
- })
|
|
|
|
- _this.endImage(2)
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- let chunkSize = 20;
|
|
|
|
- let _this = this
|
|
|
|
-
|
|
|
|
- _this.setData({
|
|
|
|
- progress: 0,
|
|
|
|
- progressPercent: 0
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- for (let i = 0; i < imageBuffer.length; i += chunkSize) {
|
|
|
|
|
|
|
|
- const chunk = imageBuffer.slice(i, i + chunkSize);
|
|
|
|
- BtHelper.wallPaperData(chunk)
|
|
|
|
- if (i >= chunkSize) {
|
|
|
|
- _this.endImage(0)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- endImage(value) {
|
|
|
|
- BtHelper.sendData(BtCmd.wallPaper(value));
|
|
|
|
- },
|
|
|
|
- startProgress() {
|
|
|
|
- let _this = this;
|
|
|
|
- this.setData({
|
|
|
|
- showProgress: true
|
|
|
|
- })
|
|
|
|
- // 定时器,每100毫秒执行一次
|
|
|
|
- let progress = 0;
|
|
|
|
- _this._timer = setInterval(function () {
|
|
|
|
- if (progress >= 100) {
|
|
|
|
- clearInterval(_this._timer); // 停止定时器
|
|
|
|
- _this.setData({
|
|
|
|
- progress: 0,
|
|
|
|
- progressPercent: 0,
|
|
|
|
- showProgress: false,
|
|
|
|
- // showCropImg: false
|
|
|
|
- });
|
|
|
|
- wx.showToast({
|
|
|
|
- title: '图片上传成功',
|
|
|
|
- })
|
|
|
|
- } else {
|
|
|
|
- progress += 1; // 每次增加1%
|
|
|
|
- _this.setData({
|
|
|
|
- progress: progress,
|
|
|
|
- progressPercent: progress
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }, 100);
|
|
|
|
- },
|
|
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
*/
|
|
@@ -303,25 +148,7 @@ Page({
|
|
console.log(param)
|
|
console.log(param)
|
|
this.wallpaperList();
|
|
this.wallpaperList();
|
|
|
|
|
|
- let _this = this;
|
|
|
|
- EventManager.addNotification(CmdEvent.eventName, function (event) {
|
|
|
|
- let name = event.cmdEvent;
|
|
|
|
- console.log("壁纸页:", event)
|
|
|
|
- switch (name) {
|
|
|
|
- case EnumCmdEvent.wallPaper:
|
|
|
|
- let otaCmd = event.wallPaper;
|
|
|
|
- let kind = event.kind;
|
|
|
|
- if (otaCmd === 1 && kind == 1) {
|
|
|
|
- // 开始发送
|
|
|
|
- _this.sendImage(_this.data.imageBuffer)
|
|
|
|
- _this.startProgress()
|
|
|
|
- } else if (otaCmd === 0 && kind == 1) {
|
|
|
|
- // 发送结束
|
|
|
|
- _this.endEnd()
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }, this)
|
|
|
|
|
|
+
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
@@ -350,7 +177,6 @@ Page({
|
|
* 生命周期函数--监听页面卸载
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
*/
|
|
onUnload() {
|
|
onUnload() {
|
|
- EventManager.removeNotification(CmdEvent.eventName, this);
|
|
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|