|
@@ -1,5 +1,14 @@
|
|
|
// pages/piano/wallpaper/wallpaper.js
|
|
|
const { deviceWallPaper } = require('../../../request/deviceListRequest')
|
|
|
+// const sharp = require('sharp');
|
|
|
+// const fs = require('fs');
|
|
|
+const {
|
|
|
+ BtHelper
|
|
|
+} = require('../../../devices/bt_helper');
|
|
|
+const { BtCmd } = require('../../../devices/bluetooth/bt_cmd');
|
|
|
+
|
|
|
+// import EventManager from '../../utils/event_bus'
|
|
|
+
|
|
|
|
|
|
Page({
|
|
|
|
|
@@ -44,6 +53,10 @@ Page({
|
|
|
showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
|
|
|
title: '壁纸设置', //导航栏 中间的标题
|
|
|
},
|
|
|
+ src: '',
|
|
|
+ width: 250,//宽度
|
|
|
+ height: 250,//高度
|
|
|
+
|
|
|
}, footerTap() {
|
|
|
const that = this;
|
|
|
wx.chooseImage({
|
|
@@ -53,25 +66,79 @@ Page({
|
|
|
success: function (res) {
|
|
|
const tempFilePaths = res.tempFilePaths;
|
|
|
console.log('获取图片信息成功', res);
|
|
|
+ wx.cropImage({
|
|
|
+ src: tempFilePaths, // 图片路径
|
|
|
+ cropScale: '1:1', // 裁剪比例
|
|
|
+ success: (res) => {
|
|
|
|
|
|
- wx.getImageInfo({
|
|
|
- src: tempFilePaths[0],
|
|
|
- success: function (imageInfo) {
|
|
|
- console.log(imageInfo);
|
|
|
- wx.navigateTo({
|
|
|
- url: `/pages/crop/crop?path=${tempFilePaths[0]}&width=${imageInfo.width}&height=${imageInfo.height}`
|
|
|
- });
|
|
|
- },
|
|
|
- fail: function (err) {
|
|
|
- console.error('获取图片信息失败', err);
|
|
|
}
|
|
|
- });
|
|
|
+ })
|
|
|
+
|
|
|
+ // wx.getImageInfo({
|
|
|
+ // src: tempFilePaths[0],
|
|
|
+ // success: function (imageInfo) {
|
|
|
+ // console.log(imageInfo);
|
|
|
+ // //获取到image-cropper实例
|
|
|
+ // //开始裁剪
|
|
|
+ // // that.setData({
|
|
|
+ // // src: imageInfo.path,//要裁剪的图片
|
|
|
+ // // })
|
|
|
+ // // wx.navigateTo({
|
|
|
+ // // url: `/pages/crop/crop?path=${tempFilePaths[0]}&width=${imageInfo.width}&height=${imageInfo.height}`
|
|
|
+ // // });
|
|
|
+ // },
|
|
|
+ // fail: function (err) {
|
|
|
+ // console.error('获取图片信息失败', err);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
},
|
|
|
fail: function (err) {
|
|
|
console.error('选择图片失败', err);
|
|
|
}
|
|
|
});
|
|
|
- }, imageTap(e) {
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ async convertToRGB565(inputPath, outputPath) {
|
|
|
+ try {
|
|
|
+ // todo
|
|
|
+ let sharp = null
|
|
|
+ const metadata = await sharp(inputPath).metadata();
|
|
|
+ const { width, height } = metadata;
|
|
|
+
|
|
|
+ const buffer = await sharp(inputPath)
|
|
|
+ .raw()
|
|
|
+ .toBuffer();
|
|
|
+
|
|
|
+ const outputBuffer = Buffer.alloc(width * height * 2); // 2 bytes per pixel for RGB565
|
|
|
+
|
|
|
+ for (let y = 0; y < height; y++) {
|
|
|
+ for (let x = 0; x < width; x++) {
|
|
|
+ const index = (y * width + x) * 4; // RGBA
|
|
|
+ const r = buffer[index];
|
|
|
+ const g = buffer[index + 1];
|
|
|
+ const b = buffer[index + 2];
|
|
|
+
|
|
|
+ const r5 = (r >> 3) & 0x1F; // 5 bits for red
|
|
|
+ const g6 = (g >> 2) & 0x3F; // 6 bits for green
|
|
|
+ const b5 = (b >> 3) & 0x1F; // 5 bits for blue
|
|
|
+
|
|
|
+ const rgb565 = (r5 << 11) | (g6 << 5) | b5;
|
|
|
+
|
|
|
+ const outputIndex = (y * width + x) * 2;
|
|
|
+ outputBuffer[outputIndex] = (rgb565 >> 8) & 0xFF; // High byte
|
|
|
+ outputBuffer[outputIndex + 1] = rgb565 & 0xFF; // Low byte
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _this.startImage()
|
|
|
+ // fs.writeFileSync(outputPath, outputBuffer);
|
|
|
+ console.log(`Conversion successful: ${outputPath}`);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error converting image:', error);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ imageTap(e) {
|
|
|
console.log(e)
|
|
|
// wxfile://tmp_d3e57489ead39c698676ff860df9cb8a37f66ee1a4777dbb.jpg
|
|
|
let image = e.currentTarget.dataset.image;
|
|
@@ -92,10 +159,28 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
|
|
|
+ startImage() {
|
|
|
+ let _this = this;
|
|
|
+ BtHelper.sendData(BtCmd.wallPaper(1));
|
|
|
+ },
|
|
|
+ sendImage(imageBuffer) {
|
|
|
+ let chunkSize = 20;
|
|
|
+ for (let i = 0; i < imageBuffer.length; i += chunkSize) {
|
|
|
+ const chunk = imageBuffer.slice(i, i + chunkSize);
|
|
|
+ // this.sendImage(chunk);
|
|
|
+ BtHelper.wallPaperData(chunk)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ endImage() {
|
|
|
+ BtHelper.sendData(BtCmd.wallPaper(0));
|
|
|
+ },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad(options) {
|
|
|
+ this.wallpaperList();
|
|
|
+
|
|
|
+ EventMan
|
|
|
|
|
|
},
|
|
|
|