From 8cf01241926a6145999859d173f3259dd81d5dfe Mon Sep 17 00:00:00 2001 From: l30052832 Date: Sat, 4 Jan 2025 12:04:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3codeCheck=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=87=BA=E6=9D=A5=E7=9A=84=E9=9D=99=E6=80=81=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/hvigorfile.ts | 6 +-- .../main/ets/constants/CameraConstants.ets | 46 +++++++++---------- .../main/ets/entryability/EntryAbility.ets | 2 +- entry/src/main/ets/pages/Index.ets | 4 +- entry/src/main/ets/utils/CameraShooter.ets | 10 ++-- entry/src/main/ets/utils/VideoRecorder.ets | 28 +++++------ hvigorfile.ts | 6 +-- 7 files changed, 51 insertions(+), 51 deletions(-) diff --git a/entry/hvigorfile.ts b/entry/hvigorfile.ts index c6edcd9..0c65754 100644 --- a/entry/hvigorfile.ts +++ b/entry/hvigorfile.ts @@ -1,6 +1,6 @@ import { hapTasks } from '@ohos/hvigor-ohos-plugin'; export default { - system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ - plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ -} + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +}; diff --git a/entry/src/main/ets/constants/CameraConstants.ets b/entry/src/main/ets/constants/CameraConstants.ets index a149e93..b2b5d73 100644 --- a/entry/src/main/ets/constants/CameraConstants.ets +++ b/entry/src/main/ets/constants/CameraConstants.ets @@ -17,93 +17,93 @@ export class CameraConstants { /** * full screen */ - static readonly FULL_SCREEN: string = '100%'; + public static readonly FULL_SCREEN: string = '100%'; /** * camera selection width */ - static readonly CENTER_WIDTH: string = '40%'; + public static readonly CENTER_WIDTH: string = '40%'; /** * time format */ - static readonly TIME_FORMAT: string = 'mm:ss.SS'; + public static readonly TIME_FORMAT: string = 'mm:ss.SS'; /** * zoom button margin top */ - static readonly PREVIEW_HEIGHT_BUTTON: number = 420; + public static readonly PREVIEW_HEIGHT_BUTTON: number = 420; /** * surface height */ - static readonly SURFACE_HEIGHT: number = 500; + public static readonly SURFACE_HEIGHT: number = 500; /** * Parameter Configuration button size */ - static readonly IMAGE_SIZE: number = 24; + public static readonly IMAGE_SIZE: number = 24; /** * Parameter Configuration button size */ - static readonly IMAGE_HEIGHT: number = 23; + public static readonly IMAGE_HEIGHT: number = 23; /** * Parameter Configuration button margin */ - static readonly MARGIN: number = 5; + public static readonly MARGIN: number = 5; /** * Parameter Configuration button margin top */ - static readonly MARGIN_TOP: number = 30; + public static readonly MARGIN_TOP: number = 30; /** * camera switch icon size */ - static readonly CAMERA_SWITCH_SIZE: number = 50; + public static readonly CAMERA_SWITCH_SIZE: number = 50; /** * capture icon size */ - static readonly CAPTURE_SIZE: number = 70; + public static readonly CAPTURE_SIZE: number = 70; /** * margin top to surface */ - static readonly MARGIN_HEIGHT: number = 10; + public static readonly MARGIN_HEIGHT: number = 10; /** * dot opacity */ - static readonly OPACITY: number = 0.2; + public static readonly OPACITY: number = 0.2; /** * dot margin left */ - static readonly MARGIN_LEFT: number = 6; + public static readonly MARGIN_LEFT: number = 6; /** * dot position */ - static readonly LEFT_DISTANCE: number = 15; + public static readonly LEFT_DISTANCE: number = 15; /** * zoom button size */ - static readonly ZOOM_SIZE: number = 35; + public static readonly ZOOM_SIZE: number = 35; /** * dot size */ - static readonly SMALL_DOT: number = 2; + public static readonly SMALL_DOT: number = 2; /** * camera preview size */ - static readonly PREVIEW_WIDTH: number = 2048; + public static readonly PREVIEW_WIDTH: number = 2048; /** * camera preview size */ - static readonly PREVIEW_HEIGHT: number = 1536; + public static readonly PREVIEW_HEIGHT: number = 1536; /** * photo size */ - static readonly PHOTO_WIDTH: number = 4160; + public static readonly PHOTO_WIDTH: number = 4160; /** * photo size */ - static readonly PHOTO_HEIGHT: number = 3120; + public static readonly PHOTO_HEIGHT: number = 3120; /** * camera preview size */ - static readonly FRONT_WIDTH: number = 4096; + public static readonly FRONT_WIDTH: number = 4096; /** * camera preview size */ - static readonly FRONT_HEIGHT: number = 3072; + public static readonly FRONT_HEIGHT: number = 3072; } \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index e203b7f..3c54dc8 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -29,7 +29,7 @@ export default class EntryAbility extends UIAbility { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); windowStage.getMainWindowSync().setWindowLayoutFullScreen(true); - AppStorage.setOrCreate('window',windowStage.getMainWindowSync()) + AppStorage.setOrCreate('window', windowStage.getMainWindowSync()) windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index bfd13d0..f350f50 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -343,7 +343,7 @@ struct XComponentPage { Column() { Row() { - Text($r("app.string.Photo")) + Text($r('app.string.Photo')) .fontColor(this.isPhoto ? Color.White : Color.Gray) .onClick(async () => { if (!this.isPhoto) { @@ -354,7 +354,7 @@ struct XComponentPage { cameraShooting(isVideo, cameraPosition, surfaceId, context, foldAbleStatus); } }) - Text($r("app.string.Video")) + Text($r('app.string.Video')) .fontColor(this.isPhoto ? Color.Gray : Color.White) .onClick(() => { if (this.isPhoto) { diff --git a/entry/src/main/ets/utils/CameraShooter.ets b/entry/src/main/ets/utils/CameraShooter.ets index cd518da..4812c35 100644 --- a/entry/src/main/ets/utils/CameraShooter.ets +++ b/entry/src/main/ets/utils/CameraShooter.ets @@ -69,15 +69,15 @@ export async function cameraShooting(isVideo: boolean, cameraPosition: number, s return profile.size.height === 1440 && profile.size.width === 1920; } return profile.size.height <= screen.width && profile.size.height >= 1080 && - (profile.size.width / profile.size.height) < (screen.height / screen.width) - && (profile.size.width / profile.size.height) > + (profile.size.width / profile.size.height) < (screen.height / screen.width) && + (profile.size.width / profile.size.height) > (foldAbleStatus === display.FoldStatus.FOLD_STATUS_EXPANDED ? 1 : 4 / 3); }); let photoProfile: undefined | camera.Profile = photoProfilesArray.find((profile: camera.Profile) => { if (previewProfile) { - return profile.size.width <= 4096 && profile.size.width >= 2448 - && profile.size.height === (foldAbleStatus === display.FoldStatus.FOLD_STATUS_EXPANDED ? 1 : - (previewProfile.size.height / previewProfile.size.width)) * profile.size.width; + return profile.size.width <= 4096 && profile.size.width >= 2448 && + profile.size.height === (foldAbleStatus === display.FoldStatus.FOLD_STATUS_EXPANDED ? 1 : + (previewProfile.size.height / previewProfile.size.width)) * profile.size.width; } return undefined; }); diff --git a/entry/src/main/ets/utils/VideoRecorder.ets b/entry/src/main/ets/utils/VideoRecorder.ets index 57e8424..e907eef 100644 --- a/entry/src/main/ets/utils/VideoRecorder.ets +++ b/entry/src/main/ets/utils/VideoRecorder.ets @@ -66,28 +66,28 @@ export async function videoRecording(isStabilization: boolean, cameraPosition: n return profile.size.height === 1080 && profile.size.width === 1920; } return profile.size.height <= screen.width && profile.size.height >= 1080 && - (profile.size.width / profile.size.height) < (screen.height / screen.width) - && (profile.size.width / profile.size.height) > + (profile.size.width / profile.size.height) < (screen.height / screen.width) && + (profile.size.width / profile.size.height) > (foldAbleStatus === display.FoldStatus.FOLD_STATUS_EXPANDED ? 1 : 16 / 9); }) let videoProfile: undefined | camera.VideoProfile = videoProfilesArray.find((profile: camera.VideoProfile) => { if (previewProfile && cameraPosition === 1) { - return profile.size.width >= 1080 && profile.size.height >= 1080 - && profile.size.height === (foldAbleStatus === display.FoldStatus.FOLD_STATUS_EXPANDED ? 1 : - (previewProfile.size.height / previewProfile.size.width)) * profile.size.width - && profile.frameRateRange.max === 30; + return profile.size.width >= 1080 && profile.size.height >= 1080 && + profile.size.height === (foldAbleStatus === display.FoldStatus.FOLD_STATUS_EXPANDED ? 1 : + (previewProfile.size.height / previewProfile.size.width)) * profile.size.width && + profile.frameRateRange.max === 30; } if (previewProfile && qualityLevel === 0) { - return profile.size.width <= 1920 && profile.size.width >= 1080 && profile.size.height >= 1080 - && profile.size.height === (foldAbleStatus === display.FoldStatus.FOLD_STATUS_EXPANDED ? 1 : - (previewProfile.size.height / previewProfile.size.width)) * profile.size.width - && profile.frameRateRange.max === 60; + return profile.size.width <= 1920 && profile.size.width >= 1080 && profile.size.height >= 1080 && + profile.size.height === (foldAbleStatus === display.FoldStatus.FOLD_STATUS_EXPANDED ? 1 : + (previewProfile.size.height / previewProfile.size.width)) * profile.size.width && + profile.frameRateRange.max === 60; } if (previewProfile && qualityLevel === 1 && cameraPosition === 0) { - return profile.size.width <= 4096 && profile.size.width >= 3000 - && profile.size.height === (foldAbleStatus === display.FoldStatus.FOLD_STATUS_EXPANDED ? 1 : - (previewProfile.size.height / previewProfile.size.width)) * profile.size.width - && profile.frameRateRange.max === 60; + return profile.size.width <= 4096 && profile.size.width >= 3000 && + profile.size.height === (foldAbleStatus === display.FoldStatus.FOLD_STATUS_EXPANDED ? 1 : + (previewProfile.size.height / previewProfile.size.width)) * profile.size.width && + profile.frameRateRange.max === 60; } return undefined; }) diff --git a/hvigorfile.ts b/hvigorfile.ts index f3cb9f1..4bbcfd1 100644 --- a/hvigorfile.ts +++ b/hvigorfile.ts @@ -1,6 +1,6 @@ import { appTasks } from '@ohos/hvigor-ohos-plugin'; export default { - system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ - plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ -} + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +}; -- Gitee From 267ae260c390cc3306619bb70de2400ce8cd6eb6 Mon Sep 17 00:00:00 2001 From: l30052832 Date: Tue, 7 Jan 2025 14:20:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Sample=E6=96=87=E6=A1=88=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 714f35d..c343c45 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# 生态应用相机实现系统级相机体验 +# 基于相机开放能力实现系统级相机 -本文针对三方相机开发场景,基于HarmonyOS提供的相机开放能力,实现系统相机级别的效果和能力,比如分辨率、动图、视频防抖、连续变焦等。 +本示例展示了如何使用HarmonyOS提供的相机开放能力,主要包括使用camera kit拍摄以及photoAccessHelper进行保存图片和视频。本示例主要适用于第三方应用调用系统相机能力,实现系统相机级别的效果和能力,比如分辨率、动图、视频防抖、连续变焦等。 ## 效果展示 -- Gitee