From c9a77754ff50cb79f0b84647d18987eaaa3701ac Mon Sep 17 00:00:00 2001 From: tongzihan <760749095@qq.com> Date: Fri, 4 Jul 2025 08:25:24 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 8 +- entry/src/main/ets/utils/CommonUtil.ets | 15 +++ .../src/main/ets/views/SettingButtonsView.ets | 110 ++++++++++++------ .../main/resources/base/element/string.json | 68 +++++++++++ 4 files changed, 163 insertions(+), 38 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 4cb6e8c..7de891e 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -14,7 +14,7 @@ */ import CameraConstant from '../constants/Constants'; -import { getClampedChildPosition, limitNumberInRange } from '../utils/CommonUtil'; +import { getClampedChildPosition, limitNumberInRange, showToast } from '../utils/CommonUtil'; import RefreshableTimer from '../utils/RefreshableTimer'; import PermissionManager from '../utils/PermissionManager'; import ZoomButtonsView from '../views/ZoomButtonsView'; @@ -295,7 +295,9 @@ struct Index { ) .funcButtonStyle() .onClick(() => { - this.isGridLineVisible = !this.isGridLineVisible + this.isGridLineVisible = !this.isGridLineVisible; + const message = this.isGridLineVisible ? $r('app.string.grid_line_open') : $r('app.string.grid_line_close'); + showToast(this.getUIContext(), message); }) } @@ -305,6 +307,8 @@ struct Index { .funcButtonStyle() .onClick(() => { this.isLevelIndicatorVisible = !this.isLevelIndicatorVisible; + const message = this.isLevelIndicatorVisible ? $r('app.string.level_open') : $r('app.string.level_close'); + showToast(this.getUIContext(), message); }) } diff --git a/entry/src/main/ets/utils/CommonUtil.ets b/entry/src/main/ets/utils/CommonUtil.ets index 3407ed4..d19b5de 100644 --- a/entry/src/main/ets/utils/CommonUtil.ets +++ b/entry/src/main/ets/utils/CommonUtil.ets @@ -63,4 +63,19 @@ export function getClampedChildPosition(childSize: Size, parentSize: Size, point top = parentSize.height - childSize.height; } return { left, top }; +} + +export function showToast( + UIContext: UIContext, + message: ResourceStr = '', + duration = 2000, + alignment = Alignment.Top, + offset: Offset = { dx: 0, dy: 300 } +) { + UIContext.getPromptAction().openToast({ + message, + duration, + alignment, + offset + }); } \ No newline at end of file diff --git a/entry/src/main/ets/views/SettingButtonsView.ets b/entry/src/main/ets/views/SettingButtonsView.ets index d1cf8b6..30d4f42 100644 --- a/entry/src/main/ets/views/SettingButtonsView.ets +++ b/entry/src/main/ets/views/SettingButtonsView.ets @@ -15,26 +15,54 @@ import { camera } from "@kit.CameraKit"; import { AVRecorderState, CameraManager, PhotoManager, PreviewManager, VideoManager } from "camera"; +import { showToast } from "../utils/CommonUtil"; import PreviewViewModel from "../viewmodels/PreviewViewModel"; +interface FlashItem { + mode: camera.FlashMode; + image: Resource; + title: ResourceStr; + toast: ResourceStr; +} + @Component struct SettingButtonsView { - private flashImageMap: Map = new Map([ - [camera.FlashMode.FLASH_MODE_CLOSE, $r('sys.symbol.camera_flash_slash')], - [camera.FlashMode.FLASH_MODE_OPEN, $r('sys.symbol.camera_flash')], - [camera.FlashMode.FLASH_MODE_AUTO, $r('sys.symbol.camera_flash_auto')], - [camera.FlashMode.FLASH_MODE_ALWAYS_OPEN, $r('sys.symbol.lightbulb_1')], - ]); - private photoFlashMenuTitleMap: Map = new Map([ - ['off', camera.FlashMode.FLASH_MODE_CLOSE], - ['on', camera.FlashMode.FLASH_MODE_OPEN], - ['auto', camera.FlashMode.FLASH_MODE_AUTO], - ['always_on', camera.FlashMode.FLASH_MODE_ALWAYS_OPEN] - ]); - private videoFlashMenuTitleMap: Map = new Map([ - ['off', camera.FlashMode.FLASH_MODE_CLOSE], - ['always_on', camera.FlashMode.FLASH_MODE_ALWAYS_OPEN] - ]); + private flashItems: FlashItem[] = [ + { + mode: camera.FlashMode.FLASH_MODE_CLOSE, + image: $r('sys.symbol.camera_flash_slash'), + title: 'off', + toast: $r('app.string.flash_close') + }, + { + mode: camera.FlashMode.FLASH_MODE_OPEN, + image: $r('sys.symbol.camera_flash'), + title: 'on', + toast: $r('app.string.flash_open') + }, + { + mode: camera.FlashMode.FLASH_MODE_AUTO, + image: $r('sys.symbol.camera_flash_auto'), + title: 'auto', + toast: $r('app.string.flash_auto') + }, + { + mode: camera.FlashMode.FLASH_MODE_ALWAYS_OPEN, + image: $r('sys.symbol.lightbulb_1'), + title: 'always_on', + toast: $r('app.string.flash_always') + } + ]; + private photoFlashModes: camera.FlashMode[] = [ + camera.FlashMode.FLASH_MODE_CLOSE, + camera.FlashMode.FLASH_MODE_OPEN, + camera.FlashMode.FLASH_MODE_AUTO, + camera.FlashMode.FLASH_MODE_ALWAYS_OPEN + ]; + private videoFlashModes: camera.FlashMode[] = [ + camera.FlashMode.FLASH_MODE_CLOSE, + camera.FlashMode.FLASH_MODE_ALWAYS_OPEN + ]; @State flashMode: camera.FlashMode = camera.FlashMode.FLASH_MODE_CLOSE; @Link isLivePhoto: boolean; @Require cameraManager: CameraManager; @@ -46,26 +74,27 @@ struct SettingButtonsView { @Link isSinglePhoto: boolean; @Link previewVM: PreviewViewModel; - getFlashMenuElements(flashMenuTitleMap: Map): MenuElement[] { - return Array.from(flashMenuTitleMap.keys()).map(text => { - const flashMode = flashMenuTitleMap.get(text); - const menuElement: MenuElement = { - value: text, - action: () => { - this.flashMode = flashMode!; - this.cameraManager.setFlashMode(this.flashMode); - } - }; - return menuElement; - }); + getFlashItem(mode: camera.FlashMode) { + return this.flashItems.find(item => item.mode === mode); } @Builder - flashButton(flashMenuElements: MenuElement[]) { - SymbolGlyph(this.flashImageMap.get(this.flashMode)) + flashButton(flashModes: camera.FlashMode[]) { + SymbolGlyph(this.getFlashItem(this.flashMode)?.image) .fontSize(22) .fontColor([Color.White]) - .bindMenu(flashMenuElements) + .bindMenu(flashModes.map(mode => { + const flashItem = this.getFlashItem(mode)!; + const menuElement: MenuElement = { + value: flashItem.title, + action: () => { + this.flashMode = mode!; + this.cameraManager.setFlashMode(mode); + showToast(this.getUIContext(), flashItem.toast); + } + }; + return menuElement; + })) } @Builder @@ -91,8 +120,10 @@ struct SettingButtonsView { ? $r('sys.symbol.livephoto') : $r('sys.symbol.livephoto_slash')) .onClick(() => { - this.isLivePhoto = !this.isLivePhoto - this.photoManager.enableMovingPhoto(this.isLivePhoto) + this.isLivePhoto = !this.isLivePhoto; + this.photoManager.enableMovingPhoto(this.isLivePhoto); + const message = this.isLivePhoto ? $r('app.string.moving_open') : $r('app.string.moving_close'); + showToast(this.getUIContext(), message); }) .fontSize(22) .fontColor([Color.White]) @@ -110,6 +141,7 @@ struct SettingButtonsView { action: () => { this.previewManager.setFrameRate(rate, rate); this.previewVM.currentRate = rate; + showToast(this.getUIContext(), $r('app.string.preview_rate', rate + 'fps')); } }; return menuElement; @@ -144,7 +176,9 @@ struct SettingButtonsView { const menuElement: MenuElement = { value: text, action: () => { - this.photoDelayTime = time! + this.photoDelayTime = time!; + const message = time ? $r('app.string.delay', text) : $r('app.string.delay_close'); + showToast(this.getUIContext(), message); } }; return menuElement; @@ -159,6 +193,8 @@ struct SettingButtonsView { .onClick(() => { this.isStabilizationEnabled = !this.isStabilizationEnabled; this.cameraManager.setVideoStabilizationMode(camera.VideoStabilizationMode.AUTO); + const message = this.isStabilizationEnabled ? $r('app.string.stabilization_enable') : $r('app.string.stabilization_disabled'); + showToast(this.getUIContext(), message); }) .fontSize(22) .fontColor([Color.White]) @@ -176,6 +212,8 @@ struct SettingButtonsView { this.isLivePhoto = false; } this.photoManager.enableMovingPhoto(this.isLivePhoto); + const message = this.isSinglePhoto ? $r('app.string.photo_single') : $r('app.string.photo_double'); + showToast(this.getUIContext(), message); }) .fontSize(22) .fontColor([Color.White]) @@ -185,7 +223,7 @@ struct SettingButtonsView { Row() { if (this.previewVM.isPhotoMode()) { this.rateButton() - this.flashButton(this.getFlashMenuElements(this.photoFlashMenuTitleMap)) + this.flashButton(this.photoFlashModes) this.delayPhotoButton(this.getPhotoDelayTimeElements()) if (!this.isSinglePhoto) { this.livePhotoButton() @@ -196,7 +234,7 @@ struct SettingButtonsView { this.videoTimerBuilder() } else { this.rateButton() - this.flashButton(this.getFlashMenuElements(this.videoFlashMenuTitleMap)) + this.flashButton(this.videoFlashModes) this.stabilizationButton() } } diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 7ebb0d5..3b59b8a 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -55,6 +55,74 @@ { "name": "video", "value": "录像" + }, + { + "name": "preview_rate", + "value": "预览帧率%d" + }, + { + "name": "delay", + "value": "延时拍照%d" + }, + { + "name": "delay_close", + "value": "延时拍照关闭" + }, + { + "name": "moving_open", + "value": "动态拍照已开启" + }, + { + "name": "moving_close", + "value": "动态拍照已关闭" + }, + { + "name": "photo_single", + "value": "单段拍照" + }, + { + "name": "photo_double", + "value": "双段拍照" + }, + { + "name": "stabilization_enable", + "value": "录像防抖已开启" + }, + { + "name": "stabilization_disabled", + "value": "录像防抖已关闭" + }, + { + "name": "grid_line_open", + "value": "网格线已开启" + }, + { + "name": "grid_line_close", + "value": "网格线已关闭" + }, + { + "name": "level_open", + "value": "水平仪已开启" + }, + { + "name": "level_close", + "value": "水平仪已关闭" + }, + { + "name": "flash_auto", + "value": "闪关灯已自动" + }, + { + "name": "flash_close", + "value": "闪光灯已关闭" + }, + { + "name": "flash_always", + "value": "闪光灯已常亮" + }, + { + "name": "flash_open", + "value": "闪光灯已开启" } ] } \ No newline at end of file -- Gitee From 7810ad082fbadd60b7a5fe3e8787ff93fd5078a4 Mon Sep 17 00:00:00 2001 From: tongzihan <15671769870@163.com> Date: Fri, 4 Jul 2025 19:49:38 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=8F=8C=E8=B7=AF=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8C=89=E9=92=AE=E6=8E=A7=E5=88=B6=E6=98=BE?= =?UTF-8?q?=E9=9A=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 19 ++++++++++++++++++- .../main/resources/base/element/string.json | 8 ++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 7de891e..054a094 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -62,6 +62,7 @@ struct Index { @State isGridLineVisible: boolean = false; @State isLevelIndicatorVisible: boolean = false; + @State isPreviewImageVisible: boolean = false; @State isFocusBoxVisible: boolean = false; @State focusBoxPosition: Edges = { top: 0, left: 0 }; @@ -312,6 +313,19 @@ struct Index { }) } + @Builder + previewImageButton() { + SymbolGlyph( + this.isPreviewImageVisible ? $r('sys.symbol.eye') : $r('sys.symbol.eye_slash') + ) + .funcButtonStyle() + .onClick(() => { + this.isPreviewImageVisible = !this.isPreviewImageVisible; + const message = this.isPreviewImageVisible ? $r('app.string.preview_image_open') : $r('app.string.preview_image_close'); + showToast(this.getUIContext(), message); + }) + } + getPreviewImageWidth() { const orientation = display.getDefaultDisplaySync().orientation; const isLandscape = orientation === display.Orientation.LANDSCAPE_INVERTED @@ -341,6 +355,7 @@ struct Index { Column({ space: 24 }) { this.gridLineButton() this.levelButton() + this.previewImageButton() } .alignRules({ top: { anchor: 'settingButtonsView', align: VerticalAlign.Bottom }, @@ -355,7 +370,9 @@ struct Index { build() { RelativeContainer() { this.preview() - this.previewImageView() + if (this.isPreviewImageVisible) { + this.previewImageView() + } this.funcButtonsView() SettingButtonsView({ previewVM: this.previewVM, diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 3b59b8a..7459b03 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -123,6 +123,14 @@ { "name": "flash_open", "value": "闪光灯已开启" + }, + { + "name": "preview_image_open", + "value": "双路预览已开启" + }, + { + "name": "preview_image_close", + "value": "双路预览已关闭" } ] } \ No newline at end of file -- Gitee From b908efb4763619688881e2204655866279c902d9 Mon Sep 17 00:00:00 2001 From: tongzihan <15671769870@163.com> Date: Sat, 5 Jul 2025 09:38:00 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=AF=B9=E7=84=A6=20?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E5=B1=8F=E5=B9=95=E6=96=B9=E5=90=91=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 16 +++++++++------- entry/src/main/ets/utils/CommonUtil.ets | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 054a094..01bfc00 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -14,7 +14,7 @@ */ import CameraConstant from '../constants/Constants'; -import { getClampedChildPosition, limitNumberInRange, showToast } from '../utils/CommonUtil'; +import { calCameraPoint, getClampedChildPosition, limitNumberInRange, showToast } from '../utils/CommonUtil'; import RefreshableTimer from '../utils/RefreshableTimer'; import PermissionManager from '../utils/PermissionManager'; import ZoomButtonsView from '../views/ZoomButtonsView'; @@ -23,7 +23,7 @@ import SettingButtonsView from '../views/SettingButtonsView'; import OperateButtonsView from '../views/OperateButtonsView'; import { sensor } from '@kit.SensorServiceKit'; import { common } from '@kit.AbilityKit'; -import { display } from '@kit.ArkUI'; +import { display, window } from '@kit.ArkUI'; import PreviewViewModel from '../viewmodels/PreviewViewModel'; import { CameraManager, GridLine, @@ -223,11 +223,13 @@ struct Index { .onClick(event => { this.isFocusBoxVisible = true; const previewSize = this.previewVM.previewSize; - // unit - const x = this.getUIContext().vp2px(event.y) / previewSize.height; - const y = 1 - this.getUIContext().vp2px(event.x) / previewSize.width; - this.cameraManager.setFocusPoint({ x, y }); - + const cameraPoint = calCameraPoint( + this.getUIContext().vp2px(event.x), + this.getUIContext().vp2px(event.y), + previewSize.width, + previewSize.height + ); + this.cameraManager.setFocusPoint(cameraPoint); this.focusBoxPosition = getClampedChildPosition(this.focusBoxSize, { width: this.getUIContext().px2vp(previewSize.width), height: this.getUIContext().px2vp(previewSize.height) diff --git a/entry/src/main/ets/utils/CommonUtil.ets b/entry/src/main/ets/utils/CommonUtil.ets index d19b5de..56b6377 100644 --- a/entry/src/main/ets/utils/CommonUtil.ets +++ b/entry/src/main/ets/utils/CommonUtil.ets @@ -14,6 +14,8 @@ */ import { Point } from "@kit.TestKit" +import { camera } from "@kit.CameraKit"; +import { display } from "@kit.ArkUI"; export function limitNumberInRange(src: number, range: number[]) { if (range.length < 2) return src; @@ -78,4 +80,18 @@ export function showToast( alignment, offset }); +} + +export function calCameraPoint(eventX: number, eventY: number, width: number, height: number): camera.Point { + const orientation = display.getDefaultDisplaySync().orientation; + if (orientation === display.Orientation.PORTRAIT) { + return { x: eventY / height, y: 1 - eventX / width }; + } + if (orientation === display.Orientation.LANDSCAPE) { + return { x: eventX / width, y: eventY / height }; + } + if (orientation === display.Orientation.PORTRAIT_INVERTED) { + return { x: 1 - eventY / height, y: eventX / width }; + } + return { x: 1 - eventX / width, y: 1 - eventY / height }; } \ No newline at end of file -- Gitee From 4f45d1f0b5bb2a2b490beca1becff1ed82441749 Mon Sep 17 00:00:00 2001 From: tongzihan <15671769870@163.com> Date: Mon, 7 Jul 2025 15:08:43 +0800 Subject: [PATCH 4/4] =?UTF-8?q?1.=E5=8D=95=E5=8F=8C=E5=BC=95=E5=8F=B7=202.?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=BA=9BisSupported=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/cameramanagers/CameraManager.ets | 22 +++++++++++---- .../cameramanagers/ImageReceiverManager.ets | 22 ++++++++------- .../main/ets/cameramanagers/OutputManager.ets | 2 +- .../ets/cameramanagers/PreviewManager.ets | 10 +++---- .../main/ets/components/LevelIndicator.ets | 4 +-- entry/src/main/ets/pages/Index.ets | 4 +-- entry/src/main/ets/utils/CommonUtil.ets | 6 ++-- .../src/main/ets/utils/PermissionManager.ets | 4 +-- entry/src/main/ets/utils/WindowUtil.ets | 4 +-- .../main/ets/viewmodels/PreviewViewModel.ets | 8 +++--- entry/src/main/ets/views/ModeButtonsView.ets | 4 +-- .../src/main/ets/views/OperateButtonsView.ets | 28 +++++++++---------- .../src/main/ets/views/SettingButtonsView.ets | 8 +++--- entry/src/main/ets/views/ZoomButtonsView.ets | 4 +-- 14 files changed, 71 insertions(+), 59 deletions(-) diff --git a/camera/src/main/ets/cameramanagers/CameraManager.ets b/camera/src/main/ets/cameramanagers/CameraManager.ets index 08cd25e..142d01f 100644 --- a/camera/src/main/ets/cameramanagers/CameraManager.ets +++ b/camera/src/main/ets/cameramanagers/CameraManager.ets @@ -13,10 +13,10 @@ * limitations under the License. */ -import { camera } from "@kit.CameraKit"; -import { Logger } from "commons/src/main/ets/utils/Logger"; -import { BusinessError } from "@kit.BasicServicesKit"; -import OutputManager, { CreateOutputConfig } from "./OutputManager"; +import { camera } from '@kit.CameraKit'; +import { Logger } from 'commons/src/main/ets/utils/Logger'; +import { BusinessError } from '@kit.BasicServicesKit'; +import OutputManager, { CreateOutputConfig } from './OutputManager'; const TAG = 'CameraManager'; @@ -78,7 +78,7 @@ export class CameraManager { await session.commitConfig(); await session.start(); this.session = session as (camera.PhotoSession | camera.VideoSession); - this.session.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO); + this.setFocusMode(camera.FocusMode.FOCUS_MODE_AUTO); } catch (e) { Logger.error(TAG, `Failed to start camera session. Cause ${JSON.stringify(e)}`); } @@ -119,6 +119,11 @@ export class CameraManager { setFocusMode(focusMode: camera.FocusMode) { try { + const isSupported = this.session?.isFocusModeSupported(focusMode); + if (!isSupported) { + Logger.error(TAG, `setFocusMode error: focus mode ${focusMode} is not supported`); + return; + } this.session?.setFocusMode(focusMode); } catch(e) { Logger.error(TAG, 'setFocusMode error ' + JSON.stringify(e)); @@ -151,6 +156,11 @@ export class CameraManager { setFlashMode(flashMode: camera.FlashMode) { try { + const isSupported = this.session?.isFlashModeSupported(flashMode); + if (!isSupported) { + Logger.error(TAG, `setFlashMode error: flash mode ${flashMode} is not supported`); + return; + } this.session?.setFlashMode(flashMode); } catch(e) { Logger.error(TAG, 'setFlashMode error ' + JSON.stringify(e)); @@ -160,7 +170,7 @@ export class CameraManager { setVideoStabilizationMode(stabilizationMode: camera.VideoStabilizationMode) { try { const session = this.session as camera.VideoSession; - let isSupported: boolean = session.isVideoStabilizationModeSupported(stabilizationMode); + const isSupported: boolean = session.isVideoStabilizationModeSupported(stabilizationMode); if (isSupported) { session.setVideoStabilizationMode(stabilizationMode); } else { diff --git a/camera/src/main/ets/cameramanagers/ImageReceiverManager.ets b/camera/src/main/ets/cameramanagers/ImageReceiverManager.ets index ce6485d..4e462fd 100644 --- a/camera/src/main/ets/cameramanagers/ImageReceiverManager.ets +++ b/camera/src/main/ets/cameramanagers/ImageReceiverManager.ets @@ -13,13 +13,13 @@ * limitations under the License. */ -import { image } from "@kit.ImageKit"; -import { camera } from "@kit.CameraKit"; -import { BusinessError } from "@kit.BasicServicesKit"; -import { Logger } from "commons/src/main/ets/utils/Logger"; -import OutputManager, { CreateOutputConfig } from "./OutputManager"; -import { display } from "@kit.ArkUI"; -import CameraConstant from "../constants/CameraConstants"; +import { image } from '@kit.ImageKit'; +import { camera } from '@kit.CameraKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { Logger } from 'commons/src/main/ets/utils/Logger'; +import OutputManager, { CreateOutputConfig } from './OutputManager'; +import { display } from '@kit.ArkUI'; +import CameraConstant from '../constants/CameraConstants'; const TAG = 'ImageReceiverManager'; @@ -82,7 +82,7 @@ export class ImageReceiverManager implements OutputManager { if (stride === width) { return await image.createPixelMap(imgComponent.byteBuffer, { size: { height: height, width: width }, - srcPixelFormat: 8, + srcPixelFormat: image.PixelMapFormat.NV21, }); } const dstBufferSize = width * height * 1.5 @@ -93,7 +93,7 @@ export class ImageReceiverManager implements OutputManager { } return await image.createPixelMap(dstArr.buffer, { size: { height: height, width: width }, - srcPixelFormat: 8, + srcPixelFormat: image.PixelMapFormat.NV21, }); } @@ -115,7 +115,9 @@ export class ImageReceiverManager implements OutputManager { const stride = imgComponent.rowStride; Logger.info(TAG, `getComponent with width:${width} height:${height} stride:${stride}`); const pixelMap = await this.getPixelMap(imgComponent, width, height, stride); - await pixelMap.rotate(this.getRotate()); + const displayRotation = display.getDefaultDisplaySync().rotation; + const rotation = this.output!.getPreviewRotation(displayRotation * camera.ImageRotation.ROTATION_90); + await pixelMap.rotate(rotation); if (this.position === camera.CameraPosition.CAMERA_POSITION_FRONT) { await pixelMap.flip(true, false); } diff --git a/camera/src/main/ets/cameramanagers/OutputManager.ets b/camera/src/main/ets/cameramanagers/OutputManager.ets index 48cb676..f5fc54f 100644 --- a/camera/src/main/ets/cameramanagers/OutputManager.ets +++ b/camera/src/main/ets/cameramanagers/OutputManager.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { camera } from "@kit.CameraKit"; +import { camera } from '@kit.CameraKit'; export interface CreateOutputConfig { cameraManager: camera.CameraManager; diff --git a/camera/src/main/ets/cameramanagers/PreviewManager.ets b/camera/src/main/ets/cameramanagers/PreviewManager.ets index ddb0f4b..cf3568b 100644 --- a/camera/src/main/ets/cameramanagers/PreviewManager.ets +++ b/camera/src/main/ets/cameramanagers/PreviewManager.ets @@ -13,11 +13,11 @@ * limitations under the License. */ -import { camera } from "@kit.CameraKit"; -import { Logger } from "commons/src/main/ets/utils/Logger"; -import { BusinessError } from "@kit.BasicServicesKit"; -import OutputManager, { CreateOutputConfig } from "./OutputManager"; -import CameraConstant from "../constants/CameraConstants"; +import { camera } from '@kit.CameraKit'; +import { Logger } from 'commons/src/main/ets/utils/Logger'; +import { BusinessError } from '@kit.BasicServicesKit'; +import OutputManager, { CreateOutputConfig } from './OutputManager'; +import CameraConstant from '../constants/CameraConstants'; const TAG_LOG = 'PreviewManager' diff --git a/camera/src/main/ets/components/LevelIndicator.ets b/camera/src/main/ets/components/LevelIndicator.ets index f594a62..341f453 100644 --- a/camera/src/main/ets/components/LevelIndicator.ets +++ b/camera/src/main/ets/components/LevelIndicator.ets @@ -13,8 +13,8 @@ * limitations under the License. */ -import { curves, display } from "@kit.ArkUI"; -import { sensor } from "@kit.SensorServiceKit"; +import { curves, display } from '@kit.ArkUI'; +import { sensor } from '@kit.SensorServiceKit'; @Component export struct LevelIndicator { diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 01bfc00..c322b3d 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -23,7 +23,7 @@ import SettingButtonsView from '../views/SettingButtonsView'; import OperateButtonsView from '../views/OperateButtonsView'; import { sensor } from '@kit.SensorServiceKit'; import { common } from '@kit.AbilityKit'; -import { display, window } from '@kit.ArkUI'; +import { display } from '@kit.ArkUI'; import PreviewViewModel from '../viewmodels/PreviewViewModel'; import { CameraManager, GridLine, @@ -93,7 +93,7 @@ struct Index { private setPreviewSize: () => void = () => { this.previewVM.setPreviewSize(); } async aboutToAppear() { - sensor.on(sensor.SensorId.ACCELEROMETER, (data) => { + sensor.on(sensor.SensorId.GRAVITY, (data) => { this.acc = data; }, { interval: 100 * 1000 * 1000 }); // 100ms this.initSleepTimer(); diff --git a/entry/src/main/ets/utils/CommonUtil.ets b/entry/src/main/ets/utils/CommonUtil.ets index 56b6377..14cce2c 100644 --- a/entry/src/main/ets/utils/CommonUtil.ets +++ b/entry/src/main/ets/utils/CommonUtil.ets @@ -13,9 +13,9 @@ * limitations under the License. */ -import { Point } from "@kit.TestKit" -import { camera } from "@kit.CameraKit"; -import { display } from "@kit.ArkUI"; +import { Point } from '@kit.TestKit'; +import { camera } from '@kit.CameraKit'; +import { display } from '@kit.ArkUI'; export function limitNumberInRange(src: number, range: number[]) { if (range.length < 2) return src; diff --git a/entry/src/main/ets/utils/PermissionManager.ets b/entry/src/main/ets/utils/PermissionManager.ets index c3d3ae4..395185a 100644 --- a/entry/src/main/ets/utils/PermissionManager.ets +++ b/entry/src/main/ets/utils/PermissionManager.ets @@ -13,8 +13,8 @@ * limitations under the License. */ -import { abilityAccessCtrl, Context, Permissions } from "@kit.AbilityKit"; -import { Logger } from "commons/src/main/ets/utils/Logger"; +import { abilityAccessCtrl, Context, Permissions } from '@kit.AbilityKit'; +import { Logger } from 'commons/src/main/ets/utils/Logger'; const TAG = 'PermissionManager'; diff --git a/entry/src/main/ets/utils/WindowUtil.ets b/entry/src/main/ets/utils/WindowUtil.ets index b533e76..bd9a970 100644 --- a/entry/src/main/ets/utils/WindowUtil.ets +++ b/entry/src/main/ets/utils/WindowUtil.ets @@ -13,8 +13,8 @@ * limitations under the License. */ -import { display, window } from "@kit.ArkUI"; -import { Logger } from "commons/src/main/ets/utils/Logger"; +import { display, window } from '@kit.ArkUI'; +import { Logger } from 'commons/src/main/ets/utils/Logger'; const TAG = 'WindowUtil' diff --git a/entry/src/main/ets/viewmodels/PreviewViewModel.ets b/entry/src/main/ets/viewmodels/PreviewViewModel.ets index d9b8db0..8876656 100644 --- a/entry/src/main/ets/viewmodels/PreviewViewModel.ets +++ b/entry/src/main/ets/viewmodels/PreviewViewModel.ets @@ -1,7 +1,7 @@ -import CameraConstant from "../constants/Constants"; -import { camera } from "@kit.CameraKit"; -import WindowUtil from "../utils/WindowUtil"; -import { display } from "@kit.ArkUI"; +import CameraConstant from '../constants/Constants'; +import { camera } from '@kit.CameraKit'; +import WindowUtil from '../utils/WindowUtil'; +import { display } from '@kit.ArkUI'; export enum CameraMode { PHOTO, diff --git a/entry/src/main/ets/views/ModeButtonsView.ets b/entry/src/main/ets/views/ModeButtonsView.ets index 8fa97a3..3b3d9fd 100644 --- a/entry/src/main/ets/views/ModeButtonsView.ets +++ b/entry/src/main/ets/views/ModeButtonsView.ets @@ -13,8 +13,8 @@ * limitations under the License. */ -import { CameraManager, PhotoManager, VideoManager } from "camera"; -import PreviewViewModel, { CameraMode } from "../viewmodels/PreviewViewModel"; +import { CameraManager, PhotoManager, VideoManager } from 'camera'; +import PreviewViewModel, { CameraMode } from '../viewmodels/PreviewViewModel'; export interface CameraModeButton { title: ResourceStr; diff --git a/entry/src/main/ets/views/OperateButtonsView.ets b/entry/src/main/ets/views/OperateButtonsView.ets index a43f7f1..bf02db4 100644 --- a/entry/src/main/ets/views/OperateButtonsView.ets +++ b/entry/src/main/ets/views/OperateButtonsView.ets @@ -13,11 +13,11 @@ * limitations under the License. */ -import { image } from "@kit.ImageKit"; -import { common } from "@kit.AbilityKit"; -import { camera } from "@kit.CameraKit"; -import PreviewViewModel from "../viewmodels/PreviewViewModel"; -import { AVRecorderState, CameraManager, PhotoManager, VideoManager } from "camera"; +import { image } from '@kit.ImageKit'; +import { common } from '@kit.AbilityKit'; +import { camera } from '@kit.CameraKit'; +import PreviewViewModel from '../viewmodels/PreviewViewModel'; +import { AVRecorderState, CameraManager, PhotoManager, VideoManager } from 'camera'; @Component struct OperateButtonsView { @@ -65,18 +65,18 @@ struct OperateButtonsView { .justifyContent(FlexAlign.Center) .onClick(() => { if (this.photoDelayTime) { - this.isDelayTakePhoto = true - this.photoRemainder = this.photoDelayTime + this.isDelayTakePhoto = true; + this.photoRemainder = this.photoDelayTime; this.photoDelayTimer = setInterval(()=>{ this.photoRemainder--; if(this.photoRemainder === 0){ - this.photoManager.capture(this.previewVM.isFront) - this.isDelayTakePhoto = false - clearTimeout(this.photoDelayTimer) + this.photoManager.capture(this.previewVM.isFront); + this.isDelayTakePhoto = false; + clearTimeout(this.photoDelayTimer); } },1000) } else { - this.photoManager.capture(this.previewVM.isFront) + this.photoManager.capture(this.previewVM.isFront); } }) } @@ -103,7 +103,7 @@ struct OperateButtonsView { }) .justifyContent(FlexAlign.Center) .onClick(() => { - this.videoManager.start() + this.videoManager.start(); }) } @@ -149,7 +149,7 @@ struct OperateButtonsView { .borderRadius('50%') .symbolEffect(new ReplaceSymbolEffect(EffectScope.WHOLE), true) .onClick(async () => { - this.videoManager.pause() + this.videoManager.pause(); }) } @@ -164,7 +164,7 @@ struct OperateButtonsView { .borderColor(Color.White) .borderRadius('50%') .onClick(async () => { - this.videoManager.resume() + this.videoManager.resume(); }) } diff --git a/entry/src/main/ets/views/SettingButtonsView.ets b/entry/src/main/ets/views/SettingButtonsView.ets index 30d4f42..c44004d 100644 --- a/entry/src/main/ets/views/SettingButtonsView.ets +++ b/entry/src/main/ets/views/SettingButtonsView.ets @@ -13,10 +13,10 @@ * limitations under the License. */ -import { camera } from "@kit.CameraKit"; -import { AVRecorderState, CameraManager, PhotoManager, PreviewManager, VideoManager } from "camera"; -import { showToast } from "../utils/CommonUtil"; -import PreviewViewModel from "../viewmodels/PreviewViewModel"; +import { camera } from '@kit.CameraKit'; +import { AVRecorderState, CameraManager, PhotoManager, PreviewManager, VideoManager } from 'camera'; +import { showToast } from '../utils/CommonUtil'; +import PreviewViewModel from '../viewmodels/PreviewViewModel'; interface FlashItem { mode: camera.FlashMode; diff --git a/entry/src/main/ets/views/ZoomButtonsView.ets b/entry/src/main/ets/views/ZoomButtonsView.ets index 1272791..ccdef47 100644 --- a/entry/src/main/ets/views/ZoomButtonsView.ets +++ b/entry/src/main/ets/views/ZoomButtonsView.ets @@ -13,8 +13,8 @@ * limitations under the License. */ -import { CameraManager } from "camera"; -import { findRangeIndex, toFixed } from "../utils/CommonUtil"; +import { CameraManager } from 'camera'; +import { findRangeIndex, toFixed } from '../utils/CommonUtil'; @Component struct ZoomButtonsView { -- Gitee