From 6874aa81f3a566fa2846f0b76a0301e2d8d13435 Mon Sep 17 00:00:00 2001 From: tongzihan <15671769870@163.com> Date: Wed, 6 Aug 2025 11:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=9D=E5=85=89=E4=B8=AD=E5=BF=83=E7=82=B9?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/cameramanagers/CameraManager.ets | 26 +++++++++++++++++++ entry/src/main/ets/pages/Index.ets | 24 ++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/camera/src/main/ets/cameramanagers/CameraManager.ets b/camera/src/main/ets/cameramanagers/CameraManager.ets index afa66c2..2300c3b 100644 --- a/camera/src/main/ets/cameramanagers/CameraManager.ets +++ b/camera/src/main/ets/cameramanagers/CameraManager.ets @@ -87,6 +87,7 @@ export class CameraManager { // [End session] this.session = session as (camera.PhotoSession | camera.VideoSession); this.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO); + this.setExposureMode(camera.ExposureMode.EXPOSURE_MODE_AUTO); } catch (e) { Logger.error(TAG, `Failed to start camera session. Cause ${JSON.stringify(e)}`); } @@ -156,6 +157,31 @@ export class CameraManager { } // [End setFocusPoint] + // [Start setExposureMode] + setExposureMode(exposureMode: camera.ExposureMode) { + try { + const isSupported = this.session?.isExposureModeSupported(exposureMode); + if (!isSupported) { + Logger.error(TAG, `setExposureMode error: focus mode ${exposureMode} is not supported`); + return; + } + this.session?.setExposureMode(exposureMode); + } catch(e) { + Logger.error(TAG, 'setExposureMode error ' + JSON.stringify(e)); + } + } + // [End setExposureMode] + + // [Start setMeteringPoint] + setMeteringPoint(point: camera.Point) { + try { + this.session?.setMeteringPoint(point); + } catch(e) { + Logger.error(TAG, 'setMeteringPoint error ' + JSON.stringify(e)); + } + } + // [End setMeteringPoint] + setZoomRatio(zoom: number) { try { this.session?.setZoomRatio(zoom); diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index c03def1..3e94243 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -75,6 +75,7 @@ struct Index { private focusBoxTimer: RefreshableTimer = new RefreshableTimer(() => { this.isFocusBoxVisible = false; }, 3 * 1000); + private exposureFontSize: number = 24; @State isSleeping: boolean = false; private sleepTimer?: RefreshableTimer; @@ -286,10 +287,11 @@ struct Index { previewSize.height ); this.cameraManager.setFocusPoint(cameraPoint); + this.cameraManager.setMeteringPoint(cameraPoint); this.focusBoxPosition = getClampedChildPosition(this.focusBoxSize, { width: this.getUIContext().px2vp(previewSize.width), height: this.getUIContext().px2vp(previewSize.height) - }, event) + }, event); this.focusBoxTimer.refresh(); }) // [EndExclude Stack] @@ -308,6 +310,10 @@ struct Index { .width(80) .height(80) .position(this.focusBoxPosition) + SymbolGlyph($r('sys.symbol.sun_max')) + .fontSize(this.exposureFontSize) + .fontColor([Color.White]) + .position(this.getExposurePosition()) } if(this.isDelayTakePhoto){ @@ -405,6 +411,22 @@ struct Index { return this.PreviewImageHeight / displayRatio; } + getExposurePosition(): Edges { + const focusBoxLeft = this.focusBoxPosition.left as number; + const focusBoxTop = this.focusBoxPosition.top as number; + const exposureWidth = this.exposureFontSize; + const exposureHeight = this.exposureFontSize; + const focusBoxWidth = this.focusBoxSize.width; + const focusBoxHeight = this.focusBoxSize.height; + const previewWidth = this.getUIContext().px2vp(this.previewVM.previewSize.width); + const GAP = 10; + const top = focusBoxTop - exposureHeight / 2 + focusBoxHeight / 2; + const left = focusBoxLeft > previewWidth / 2 + ? focusBoxLeft - GAP - exposureWidth + : focusBoxLeft + focusBoxWidth + GAP; + return { top, left }; + } + @Builder previewImageView() { Image(this.previewImage) -- Gitee