diff --git a/camera/src/main/ets/cameramanagers/CameraManager.ets b/camera/src/main/ets/cameramanagers/CameraManager.ets index afa66c2f16c55000671b4b500828a79d7a17226e..2300c3bacc64001c73ff20ed27149d3220dc5039 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 c03def17a669be99dd3b5d2f72a2ec59f3ee69c4..3e9424333fe9bb3251e2623f0bdfdbf6ec78b374 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)