chenjiabao пре 3 месеци
родитељ
комит
56a1ac20ab

+ 5 - 5
build-profile.json5

@@ -21,13 +21,13 @@
       {
         "name": "default",
         "material": {
-          "certpath": "C:/Users/Administrator/.ohos/config/openharmony/default_ohos-station-web_3PrdxSBaGcCfy9Hg5yBarasQHvqCqV0r5a8yksCRxCU=.cer",
-          "storePassword": "0000001AD2318F0F8B29F4443C8F5D4FF192CE44AE632F559ED4D59B3E82D3E1481B19A2A8B2CCB9347A",
+          "certpath": "C:/Users/cjbll/.ohos/config/openharmony/default_common-station-web_RjeHrjh9AQjRCeMQeLAaz553iKzjsb9y48IsCPLaHI4=.cer",
+          "storePassword": "0000001B007AF605BC49A8B5F50C4BB43CF52785E84D6C844987808974046C45E5F5713240387A132CBEB3",
           "keyAlias": "debugKey",
-          "keyPassword": "0000001A24B7D29C1F84799AD8148067EFEC319517127B4F21D1F4DAD23D96F6336F01C62810465320D4",
-          "profile": "C:/Users/Administrator/.ohos/config/openharmony/default_ohos-station-web_3PrdxSBaGcCfy9Hg5yBarasQHvqCqV0r5a8yksCRxCU=.p7b",
+          "keyPassword": "0000001BE31ED14F078D24834DBAE7C57C1820C41158517DAFBDF576ECAA6AADD3EE905FF16A7E708AB130",
+          "profile": "C:/Users/cjbll/.ohos/config/openharmony/default_common-station-web_RjeHrjh9AQjRCeMQeLAaz553iKzjsb9y48IsCPLaHI4=.p7b",
           "signAlg": "SHA256withECDSA",
-          "storeFile": "C:/Users/Administrator/.ohos/config/openharmony/default_ohos-station-web_3PrdxSBaGcCfy9Hg5yBarasQHvqCqV0r5a8yksCRxCU=.p12"
+          "storeFile": "C:/Users/cjbll/.ohos/config/openharmony/default_common-station-web_RjeHrjh9AQjRCeMQeLAaz553iKzjsb9y48IsCPLaHI4=.p12"
         }
       }
     ]

+ 104 - 52
entry/src/main/ets/pages/CameraVersion2.ets

@@ -8,7 +8,6 @@ import CommonEventManager from '@ohos.commonEventManager'
 import uploadInstance from '../utils/UploadUtil';
 import router from '@ohos.router';
 import fileIo from '@ohos.file.fs';
-
 const TAG = "openHarmonyBridge upload"
 @Entry
 @Component
@@ -203,60 +202,32 @@ struct Index {
   readTimer = 0
 
   liveShow = async () => {
-    const context: Context = getContext(this);
+
+    const previewManager = new PreviewManager(getContext(this));
     let index = 0;
-    let lastImagePath = '';
 
-     this.readTimer = setInterval( async () => {
-      if (!this.isCloseView) {
+    this.readTimer = setInterval(async () => {
+      if (!this.isCloseView && !this.isCapturing) {
         try {
-          if(!this.isCapturing) {
-            const filePath: string = `${context.filesDir}/live${index}.jpg`;
-            // 检查文件是否存在
-            try {
-              fs.accessSync(filePath);
-
-              // 只有当文件路径改变时才更新图像
-              if (filePath !== lastImagePath) {
-                const imageSource = image.createImageSource(filePath);
-                if (imageSource) {
-                  try {
-                    // 创建新的PixelMap之后再释放旧的
-                    const newPixelMap = await imageSource.createPixelMap();
-                    if (this.commodityPixelMap) {
-                      this.commodityPixelMap.release();
-                    }
-                    this.commodityPixelMap = newPixelMap;
-                    imageSource.release();
-                    lastImagePath = filePath;
-                    index = (index + 1) % 10;
-                  } catch(error) {
-                    console.error(TAG, "创建PixelMap失败:", error);
-                    router.back()
-                    // break
-                  }
-                }
-              }
-            } catch (error) {
-              // await sleep(30);
-              // continue;
-            }
-
+          const success = await previewManager.processFrame(index);
+          if (success) {
+            this.commodityPixelMap = previewManager.getActiveBuffer();
+            //index = (index + 1) % 10;
           }
-          // 减小循环间隔提高流畅度
-
         } catch (error) {
-          console.error(TAG, "预览错误:", error);
-
+          console.warn(TAG, "预览更新失败:", error);
         }
       }
-    }, 50)
-
-    // 退出时清理资源
-    if(this.commodityPixelMap) {
-      this.commodityPixelMap.release();
-      this.commodityPixelMap = null;
-    }
+    }, 50); // 30ms interval for ~30fps
+
+    // 清理资源
+    return () => {
+      previewManager.release();
+      if (this.commodityPixelMap) {
+        this.commodityPixelMap.release();
+        this.commodityPixelMap = null;
+      }
+    };
   };
 
   aboutToAppear(): void {
@@ -272,10 +243,14 @@ struct Index {
     if (this.subscriber) {
       CommonEventManager.unsubscribe(this.subscriber);
     }
-
-    clearInterval(this.readTimer)
+    if (this.readTimer) {
+      clearInterval(this.readTimer);
+    }
+    if (this.commodityPixelMap) {
+      this.commodityPixelMap.release();
+      this.commodityPixelMap = null;
+    }
   }
-
   build() {
     Column() {
       Row() {
@@ -465,4 +440,81 @@ function delayExecution(callback: Function, delay: number) {
     clearInterval(timerId);
     callback();
   }, delay);
-}
+}
+
+class PreviewManager {
+  private context: Context;
+  private activeBuffer: PixelMap | null = null;
+  private nextBuffer: PixelMap | null = null;
+  private isProcessing: boolean = false;
+  private lastFrameTime: number = 0;
+  private frameInterval: number = 50;
+
+  constructor(context: Context) {
+    this.context = context;
+  }
+
+  async processFrame(index: number): Promise<boolean> {
+    if (this.isProcessing) return false;
+
+    const now = Date.now();
+    if (now - this.lastFrameTime < this.frameInterval) {
+      return false;
+    }
+
+    this.isProcessing = true;
+    try {
+      const filePath = `${this.context.filesDir}/live${index}.jpg`;
+
+      // 检查文件是否存在
+      try {
+        fs.accessSync(filePath);
+      } catch {
+        this.isProcessing = false;
+        return false;
+      }
+
+      const imageSource = image.createImageSource(filePath);
+      if (!imageSource) {
+        this.isProcessing = false;
+        return false;
+      }
+
+      // 创建较小尺寸的PixelMap以提高性能
+
+      this.nextBuffer = await imageSource.createPixelMap();
+      imageSource.release();
+
+      // 交换缓冲区
+      if (this.activeBuffer) {
+        this.activeBuffer.release();
+      }
+      this.activeBuffer = this.nextBuffer;
+      this.nextBuffer = null;
+      this.lastFrameTime = now;
+      return true;
+    } catch (error) {
+      console.warn(TAG, "处理预览帧失败:", error);
+      return false;
+    } finally {
+      this.isProcessing = false;
+    }
+  }
+
+  getActiveBuffer(): PixelMap | null {
+    return this.activeBuffer;
+  }
+
+  release() {
+    if (this.activeBuffer) {
+      this.activeBuffer.release();
+      this.activeBuffer = null;
+    }
+    if (this.nextBuffer) {
+      this.nextBuffer.release();
+      this.nextBuffer = null;
+    }
+  }
+}
+
+

+ 7 - 8
entry/src/main/ets/pages/Index.ets

@@ -6,9 +6,8 @@ import uploadInstance from "../utils/UploadUtil"
 
 const TAG = "openHarmonyBridge" //webview和vue沟通的名称
 // const webUrl = "http://192.168.1.4:11000/"  //创客前端服务
-const webUrl = "http://192.168.0.49:3005/"  //本地跑的项目
-
-// const webUrl = "http://10.88.11.201:11000/"  //险峰服务
+//const webUrl = "http://192.168.0.49:3005/"  //本地跑的项目
+const webUrl = "http://10.88.11.200:11000/"  //险峰服务
 
 class BridgeModel {
   constructor() {
@@ -81,11 +80,11 @@ struct Index {
       // 这个webview调用相机不知道为什么只能执行一次,选择文件的回到还行,但是为了统一写法还是用registerJavaScriptProxy,但是有时候注册的方法也只能执行一次,不知道为什么。
       // Web({ src: $rawfile('doc_old.html'), controller: this.controller })//测试官方文档 这个是好使的
 
-      // Button("跳转到相机页面").onClick(() => {
-      //   router.pushUrl({
-      //     url: "pages/CameraVersion2"
-      //   })
-      // })
+      Button("跳转到相机页面").onClick(() => {
+        router.pushUrl({
+          url: "pages/CameraVersion2"
+        })
+      })
       Web({
         src: webUrl,
         controller: this.controller

+ 2 - 2
entry/src/main/ets/utils/Request.ets

@@ -13,8 +13,8 @@ import RequestParamsModel from './requestParams';
 import uploadInstance from './UploadUtil';
 
 // jxq: 项目基本请求路径 险峰的
-// export  const JGRequestBaseUrl = "http://10.88.11.200:8079/" //险峰
-export  const JGRequestBaseUrl = "http://192.168.1.4:8079/" // 创客
+export  const JGRequestBaseUrl = "http://10.88.11.200:8079/" //险峰
+//export  const JGRequestBaseUrl = "http://192.168.1.4:8079/" // 创客
 
 const DEBUG = true //