From 6cc27249a2131d0651240badfcdad64ff9b96d54 Mon Sep 17 00:00:00 2001 From: l30052832 Date: Sat, 21 Dec 2024 18:31:34 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E9=80=82=E9=85=8Dmate70=E7=B3=BB?= =?UTF-8?q?=E5=88=97=E8=A7=86=E9=A2=91=E5=BD=95=E5=83=8F=202=E3=80=81?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmate70=E7=B3=BB=E5=88=97=E4=BB=8E=E4=B8=80?= =?UTF-8?q?=E5=80=8D=E5=88=B0=E5=B9=BF=E8=A7=92=E5=8F=98=E7=84=A6=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/constants/CameraConstants.ets | 2 +- entry/src/main/ets/pages/Index.ets | 283 +++++++++--------- entry/src/main/ets/utils/CameraShooter.ets | 2 + entry/src/main/ets/utils/VideoRecorder.ets | 8 +- 4 files changed, 146 insertions(+), 149 deletions(-) diff --git a/entry/src/main/ets/constants/CameraConstants.ets b/entry/src/main/ets/constants/CameraConstants.ets index 2aa8af9..a149e93 100644 --- a/entry/src/main/ets/constants/CameraConstants.ets +++ b/entry/src/main/ets/constants/CameraConstants.ets @@ -29,7 +29,7 @@ export class CameraConstants { /** * zoom button margin top */ - static readonly PREVIEW_HEIGHT_BUTTON: number = 350; + static readonly PREVIEW_HEIGHT_BUTTON: number = 420; /** * surface height */ diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 9027c26..bfd13d0 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -76,6 +76,7 @@ struct XComponentPage { // Is recording now @State recording: boolean = false; @State isFoldAble: boolean = display.isFoldable(); + @State foldAbleStatus: number = this.isFoldAble ? display.getFoldStatus() : FoldStatus.FOLD_STATUS_UNKNOWN; @StorageLink('photoUri') photoUri: string | Resource | PixelMap = ''; // Indicates whether the current preview type is an image @State currentPic: boolean = true; @@ -112,15 +113,12 @@ struct XComponentPage { setTimeout(async () => { if (this.isFoldAble) { foldAbleStatus = display.getFoldStatus(); - this.mXComponentController.setXComponentSurfaceRect({ - surfaceWidth: foldAbleStatus === 1 ? 1400 : display.getDefaultDisplaySync().width, - surfaceHeight: this.isFoldAble ? 1400 : 1600 - }) display.on('foldStatusChange', (foldStatus: display.FoldStatus) => { if (foldStatus === 3) { return; } foldAbleStatus = foldStatus; + this.foldAbleStatus = foldStatus; if (foldStatus === 1) { cameraPosition = cameraPosition === 0 ? 0 : 2; } else { @@ -128,8 +126,10 @@ struct XComponentPage { } setTimeout(() => { this.mXComponentController.setXComponentSurfaceRect({ - surfaceWidth: foldAbleStatus === 1 ? 1400 : display.getDefaultDisplaySync().width, - surfaceHeight: this.isFoldAble ? 1400 : 1600 + surfaceWidth: this.foldAbleStatus === FoldStatus.FOLD_STATUS_EXPANDED ? 1400 : + display.getDefaultDisplaySync().width, + surfaceHeight: this.isFoldAble && foldAbleStatus === FoldStatus.FOLD_STATUS_EXPANDED ? 1400 : + display.getDefaultDisplaySync().width * (this.isPhoto ? 4 / 3 : 16 / 9) }) cameraShooting(isVideo, cameraPosition, surfaceId, context, foldAbleStatus); }, 500) @@ -260,8 +260,7 @@ struct XComponentPage { Stack() { XComponent({ - id: '', - type: 'surface', + type: XComponentType.SURFACE, controller: this.mXComponentController }) .gesture( @@ -275,41 +274,30 @@ struct XComponentPage { } else if (this.zoom < zoomRatioRange[0]) { this.zoom = zoomRatioRange[0]; } - if (this.isPhoto) { - setPhotoZoom(this.zoom); - } else { - setVideoZoom(this.zoom); - } + this.isPhoto ? setPhotoZoom(this.zoom) : setVideoZoom(this.zoom) } }) .onActionEnd(() => { - if (this.isPhoto) { - currentFov = getPhotoZoom(); - } else { - currentFov = getVideoZoom(); - } - this.isShowZoom = false + this.isPhoto ? currentFov = getPhotoZoom() : currentFov = getVideoZoom(); + this.isShowZoom = false; }) ) .onLoad(async () => { this.mXComponentController.setXComponentSurfaceRect({ - surfaceWidth: foldAbleStatus === 1 ? 1400 : display.getDefaultDisplaySync().width, - surfaceHeight: this.isFoldAble ? 1400 : 1600 + surfaceWidth: this.foldAbleStatus === FoldStatus.FOLD_STATUS_EXPANDED ? 1400 : + display.getDefaultDisplaySync().width, + surfaceHeight: this.foldAbleStatus === FoldStatus.FOLD_STATUS_EXPANDED ? 1400 : + display.getDefaultDisplaySync().width * 4 / 3 }); surfaceId = this.mXComponentController.getXComponentSurfaceId(); }) - .height(CameraConstants.SURFACE_HEIGHT); + .height(this.isPhoto || this.foldAbleStatus === FoldStatus.FOLD_STATUS_EXPANDED ? 500 : 670); Row() { Image(0 < this.zoom && this.zoom < 1 ? $r('app.media.W_0') : $r('app.media.W')) .height(CameraConstants.ZOOM_SIZE) .onClick(() => { this.zoom = zoomRatioRange[0]; - currentFov = this.zoom; - if (this.isPhoto) { - setPhotoZoom(this.zoom); - } else { - setVideoZoom(this.zoom); - } + this.setZoom(); }); Image($r('app.media.small_2x')) .height(CameraConstants.SMALL_DOT) @@ -346,132 +334,135 @@ struct XComponentPage { }) } .visibility(this.isFront || this.isStabilization ? Visibility.Hidden : Visibility.Visible) - .margin({ top: this.isFoldAble ? CameraConstants.PREVIEW_HEIGHT_BUTTON : 400 }) + .margin({ top: this.isFoldAble ? CameraConstants.PREVIEW_HEIGHT_BUTTON : 450 }) Text(this.zoom === zoomRatioRange[0] ? 'wide angle' : this.zoom.toFixed(1) + 'x') .fontColor(Color.White) .margin({ top: 250 }) .visibility(this.isShowZoom && !this.isFront ? Visibility.Visible : Visibility.Hidden) - } - - Row() { - Text($r("app.string.Photo")) - .fontColor(this.isPhoto ? Color.White : Color.Gray) - .onClick(async () => { - if (!this.isPhoto) { - this.isPhoto = true; - isVideo = false; - stopRecordPreview(); - this.Initialize(); - cameraShooting(isVideo, cameraPosition, surfaceId, context, foldAbleStatus); - } - }) - Text($r("app.string.Video")) - .fontColor(this.isPhoto ? Color.Gray : Color.White) - .onClick(() => { - if (this.isPhoto) { - this.isPhoto = false; - releaseCamera(); - // 1080P - this.Initialize(); - videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, context, foldAbleStatus); - isVideo = true; - } - }) - } - .visibility(this.recording ? Visibility.Hidden : Visibility.Visible) - .justifyContent(FlexAlign.SpaceAround) - .width(CameraConstants.CENTER_WIDTH) - .height(CameraConstants.CAPTURE_SIZE) - .margin({ bottom: CameraConstants.MARGIN_HEIGHT }) - Row() { - Image(this.photoUri) - .borderWidth(this.photoUri === '' ? 0 : 1) + Column() { + Row() { + Text($r("app.string.Photo")) + .fontColor(this.isPhoto ? Color.White : Color.Gray) + .onClick(async () => { + if (!this.isPhoto) { + this.isPhoto = true; + isVideo = false; + stopRecordPreview(); + this.Initialize(); + cameraShooting(isVideo, cameraPosition, surfaceId, context, foldAbleStatus); + } + }) + Text($r("app.string.Video")) + .fontColor(this.isPhoto ? Color.Gray : Color.White) + .onClick(() => { + if (this.isPhoto) { + this.isPhoto = false; + releaseCamera(); + // 1080P + this.Initialize(); + videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, context, + foldAbleStatus); + isVideo = true; + } + }) + } .visibility(this.recording ? Visibility.Hidden : Visibility.Visible) - .borderColor(Color.White) - .height(CameraConstants.CAMERA_SWITCH_SIZE) - .width(CameraConstants.CAMERA_SWITCH_SIZE) - .borderRadius(CameraConstants.CAMERA_SWITCH_SIZE / 2) - .rotate({ angle: this.rotation }) - .animation({ curve: curves.springMotion() }) - .onClick(() => { - if (this.photoUri !== '') { - if (this.currentPic) { - previewPhoto(context); - } else { - previewVideo(context, videoUri); - } - } - }) - Stack() { - Image($r('app.media.capture')) - .height(CameraConstants.CAPTURE_SIZE) - .visibility(this.isPhoto ? Visibility.Visible : Visibility.Hidden) - .onClick(() => { - capture(this.isFront); - this.currentPic = true; - }) - Image($r('app.media.record')) - .height(CameraConstants.CAPTURE_SIZE) - .visibility(this.isPhoto ? Visibility.Hidden : this.recording ? Visibility.Hidden : Visibility.Visible) - .onClick(async () => { - startRecord(); - this.textTimerController.start(); - this.recording = true; - }) - Image($r('app.media.recording')) - .visibility(this.isPhoto ? Visibility.Hidden : this.recording ? Visibility.Visible : Visibility.Hidden) - .height(CameraConstants.CAPTURE_SIZE) - .onClick(async () => { - this.textTimerController.reset(); - this.recording = false; - this.currentPic = false; - this.zoom = 1; - currentFov = 1; - this.flashPic = $r('app.media.ic_camera_public_flash_off'); - videoUri = await stopRecord(); - stopRecordPreview(); - videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, context, foldAbleStatus); - setTimeout(() => { - this.getThumbnail(); - }, 500); - }) - } + .justifyContent(FlexAlign.SpaceAround) + .width(CameraConstants.CENTER_WIDTH) + .height(CameraConstants.CAPTURE_SIZE) + .margin({ bottom: CameraConstants.MARGIN_HEIGHT }) - Image($r('app.media.switch_camera')) - .height(CameraConstants.CAMERA_SWITCH_SIZE) - .visibility(this.recording ? Visibility.Hidden : Visibility.Visible) - .onClick(async () => { - if (this.isFoldAble) { - foldAbleStatus = display.getFoldStatus(); - if (foldAbleStatus === 1) { - cameraPosition = cameraPosition === 0 ? 2 : 0; - } else { - cameraPosition = cameraPosition === 1 ? 0 : 1; - } - } else { - cameraPosition = cameraPosition === 1 ? 0 : 1 + Row() { + Image(this.photoUri) + .borderWidth(this.photoUri === '' ? 0 : 1) + .visibility(this.recording ? Visibility.Hidden : Visibility.Visible) + .borderColor(Color.White) + .height(CameraConstants.CAMERA_SWITCH_SIZE) + .width(CameraConstants.CAMERA_SWITCH_SIZE) + .borderRadius(CameraConstants.CAMERA_SWITCH_SIZE / 2) + .rotate({ angle: this.rotation }) + .animation({ curve: curves.springMotion() }) + .onClick(() => { + if (this.photoUri !== '') { + this.currentPic ? previewPhoto(context) : previewVideo(context, videoUri); + } + }) + Stack() { + Image($r('app.media.capture')) + .height(CameraConstants.CAPTURE_SIZE) + .visibility(this.isPhoto ? Visibility.Visible : Visibility.Hidden) + .onClick(() => { + capture(this.isFront); + this.currentPic = true; + }) + Image($r('app.media.record')) + .height(CameraConstants.CAPTURE_SIZE) + .visibility(this.isPhoto ? Visibility.Hidden : this.recording ? Visibility.Hidden : Visibility.Visible) + .onClick(async () => { + startRecord(); + this.textTimerController.start(); + this.recording = true; + }) + Image($r('app.media.recording')) + .visibility(this.isPhoto ? Visibility.Hidden : this.recording ? Visibility.Visible : Visibility.Hidden) + .height(CameraConstants.CAPTURE_SIZE) + .onClick(async () => { + this.textTimerController.reset(); + this.recording = false; + this.currentPic = false; + this.zoom = 1; + currentFov = 1; + this.flashPic = $r('app.media.ic_camera_public_flash_off'); + videoUri = await stopRecord(); + stopRecordPreview(); + videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, context, + foldAbleStatus); + setTimeout(() => { + this.getThumbnail(); + }, 500); + }) } - if (this.isPhoto) { - cameraShooting(isVideo, cameraPosition, surfaceId, context, foldAbleStatus); - } else { - stopRecordPreview(); - videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, context, foldAbleStatus); - } - this.Initialize(); - this.isFront = cameraPosition !== 0; - }) - } - .width(CameraConstants.FULL_SCREEN) - .justifyContent(FlexAlign.SpaceAround) + Image($r('app.media.switch_camera')) + .height(CameraConstants.CAMERA_SWITCH_SIZE) + .visibility(this.recording ? Visibility.Hidden : Visibility.Visible) + .onClick(async () => { + if (this.isFoldAble) { + foldAbleStatus = display.getFoldStatus(); + if (foldAbleStatus === 1) { + cameraPosition = cameraPosition === 0 ? 2 : 0; + } else { + cameraPosition = cameraPosition === 1 ? 0 : 1; + } + } else { + cameraPosition = cameraPosition === 1 ? 0 : 1 + } - TextTimer({ controller: this.textTimerController }) - .format(CameraConstants.TIME_FORMAT) - .fontColor(Color.White) - .fontSize(CameraConstants.MARGIN_TOP) - .visibility(this.recording ? Visibility.Visible : Visibility.Hidden) + if (this.isPhoto) { + cameraShooting(isVideo, cameraPosition, surfaceId, context, foldAbleStatus); + } else { + stopRecordPreview(); + videoRecording(this.isStabilization, cameraPosition, qualityLevel, surfaceId, context, + foldAbleStatus); + } + this.Initialize(); + this.isFront = cameraPosition !== 0; + }) + } + .width(CameraConstants.FULL_SCREEN) + .justifyContent(FlexAlign.SpaceAround) + + TextTimer({ controller: this.textTimerController }) + .format(CameraConstants.TIME_FORMAT) + .fontColor(Color.White) + .fontSize(CameraConstants.MARGIN_TOP) + .visibility(this.recording ? Visibility.Visible : Visibility.Hidden) + } + .margin({ top: 500 }) + } + .alignContent(Alignment.Top) } .height(CameraConstants.FULL_SCREEN) .backgroundColor(Color.Black) @@ -483,6 +474,12 @@ struct XComponentPage { this.isStabilization = false; this.flashPic = $r('app.media.ic_camera_public_flash_off'); this.isMovingPhoto = false; + this.mXComponentController.setXComponentSurfaceRect({ + surfaceWidth: this.foldAbleStatus === FoldStatus.FOLD_STATUS_EXPANDED ? 1400 : + display.getDefaultDisplaySync().width, + surfaceHeight: this.isFoldAble && this.foldAbleStatus === FoldStatus.FOLD_STATUS_EXPANDED ? 1400 : + display.getDefaultDisplaySync().width * (this.isPhoto ? 4 / 3 : 16 / 9) + }) } switchFlash(flashMode: number): void { diff --git a/entry/src/main/ets/utils/CameraShooter.ets b/entry/src/main/ets/utils/CameraShooter.ets index 3b9981f..cd518da 100644 --- a/entry/src/main/ets/utils/CameraShooter.ets +++ b/entry/src/main/ets/utils/CameraShooter.ets @@ -19,6 +19,7 @@ import { BusinessError } from '@kit.BasicServicesKit'; import { photoAccessHelper } from '@kit.MediaLibraryKit'; import { common } from '@kit.AbilityKit'; import { display } from '@kit.ArkUI'; +import { colorSpaceManager } from '@kit.ArkGraphics2D'; let previewOutput: camera.PreviewOutput; let cameraInput: camera.CameraInput; @@ -99,6 +100,7 @@ export async function cameraShooting(isVideo: boolean, cameraPosition: number, s photoSession.addInput(cameraInput); photoSession.addOutput(previewOutput); photoSession.addOutput(photoOutPut); + photoSession.setColorSpace(colorSpaceManager.ColorSpace.DISPLAY_P3); await photoSession.commitConfig(); await photoSession.start(); // Check whether the device supports the flash. diff --git a/entry/src/main/ets/utils/VideoRecorder.ets b/entry/src/main/ets/utils/VideoRecorder.ets index c850939..57e8424 100644 --- a/entry/src/main/ets/utils/VideoRecorder.ets +++ b/entry/src/main/ets/utils/VideoRecorder.ets @@ -62,15 +62,13 @@ export async function videoRecording(isStabilization: boolean, cameraPosition: n } let previewProfile: undefined | camera.Profile = previewProfilesArray.find((profile: camera.Profile) => { let screen = display.getDefaultDisplaySync(); - if (screen.width <= 1080) { - return profile.size.height === 1080 && profile.size.width === 1440; - } else if (screen.width <= 1440 && screen.width > 1080) { - return profile.size.height === 1440 && profile.size.width === 1920; + if (screen.width <= 1440 ) { + 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) > - (foldAbleStatus === display.FoldStatus.FOLD_STATUS_EXPANDED ? 1 : 4 / 3); + (foldAbleStatus === display.FoldStatus.FOLD_STATUS_EXPANDED ? 1 : 16 / 9); }) let videoProfile: undefined | camera.VideoProfile = videoProfilesArray.find((profile: camera.VideoProfile) => { if (previewProfile && cameraPosition === 1) { -- Gitee