diff --git a/DealStrideSolution/README.en.md b/DealStrideSolution/README.en.md
index b5baebfd466eb02fa62ee32c51caf7f0a1792f8d..ad911c2aac9253a6a77f27e6e28cd9cda9114e60 100644
--- a/DealStrideSolution/README.en.md
+++ b/DealStrideSolution/README.en.md
@@ -9,7 +9,7 @@ After obtaining the preview stream buffer of each frame, if the image is stacked
| Positive Example 1 | Positive Example 2 |
|----------------------------------------------------------|----------------------------------------------------------|
|
|
|
-
+The images are for reference only. The actual camera preview and captured images shall prevail.
## How to Use
1. Tap the **Negative example: unprocessed stride** button to redirect to the child page **NoDealStride**. The camera preview stream is displayed on the child page, and an artifact appears.
diff --git a/DealStrideSolution/README.md b/DealStrideSolution/README.md
index 0cc10bb6b468de7458845ede8f643d66e83a63aa..976739109a73b0e9b4b303115c120f56b1d8bd27 100644
--- a/DealStrideSolution/README.md
+++ b/DealStrideSolution/README.md
@@ -9,7 +9,7 @@
| 正例一 | 正例二 |
|----------------------------------------------------------|----------------------------------------------------------|
|
|
|
-
+图片仅作参考,具体相机预览效果,与实际使用时拍摄画面为主。
## 使用说明
1、父页面点击"反例:未处理stride"按钮,跳转子页面NoDealStride,子页面的预览界面展示相机预览流,出现花屏现象。
diff --git a/DealStrideSolution/entry/src/main/ets/common/Constants.ts b/DealStrideSolution/entry/src/main/ets/common/Constants.ts
index 03df7571d5a91b53aa0db128f7ea8c9798272b81..caeead495d922b60357f8b0cdcdda68310521728 100644
--- a/DealStrideSolution/entry/src/main/ets/common/Constants.ts
+++ b/DealStrideSolution/entry/src/main/ets/common/Constants.ts
@@ -17,9 +17,9 @@ export class Constants {
/**
* Surface width in xComponent.
*/
- static readonly X_COMPONENT_SURFACE_WIDTH = 1080; // 1080*1080 stride->1088
+ static readonly X_COMPONENT_SURFACE_WIDTH: number = 1080; // 1080*1080 stride->1088
/**
* Surface height in xComponent.
*/
- static readonly X_COMPONENT_SURFACE_HEIGHT = 1080;
+ static readonly X_COMPONENT_SURFACE_HEIGHT: number = 1080;
};
\ No newline at end of file
diff --git a/DealStrideSolution/entry/src/main/ets/pages/PageTwo.ets b/DealStrideSolution/entry/src/main/ets/pages/PageTwo.ets
index c4ced48b69f33f39426570c50ba51e6c65cd8617..d98c2c50d0593a40d53b06c11ac3bf780b6de501 100644
--- a/DealStrideSolution/entry/src/main/ets/pages/PageTwo.ets
+++ b/DealStrideSolution/entry/src/main/ets/pages/PageTwo.ets
@@ -80,7 +80,7 @@ export struct PageTwo {
try {
this.getUIContext().getPromptAction().showToast({ message: $r('app.string.only_show_for_ux') })
} catch (error) {
- let err = error as BusinessError;
+ let err: BusinessError = error as BusinessError;
hilog.warn(0x000, 'testTag', `showToast failed, code=${err.code}, message=${err.message}`);
}
})
diff --git a/DealStrideSolution/entry/src/main/ets/utils/CameraServiceOne.ets b/DealStrideSolution/entry/src/main/ets/utils/CameraServiceOne.ets
index 69bf1df1917d590233b1484830091767edc25224..4440239923c516125738f75a773a4a4fa7b13a13 100644
--- a/DealStrideSolution/entry/src/main/ets/utils/CameraServiceOne.ets
+++ b/DealStrideSolution/entry/src/main/ets/utils/CameraServiceOne.ets
@@ -58,13 +58,13 @@ class CameraService {
if (nextImage) {
nextImage.getComponent(image.ComponentType.JPEG,
async (err, component: image.Component) => {
- let width = 1080; // Application create preview stream resolution corresponding to the width
- let height = 1080; // Application create preview stream resolution corresponding to the height
- let stride = component.rowStride; // Get stride by using component.rowStride
+ let width: number = 1080; // Application create preview stream resolution corresponding to the width
+ let height: number = 1080; // Application create preview stream resolution corresponding to the height
+ let stride: number = component.rowStride; // Get stride by using component.rowStride
Logger.info(TAG, `receiver getComponent width:${width} height:${height} stride:${stride}`);
// Positive example: Case 1.stride and width are equal. Reading buffer by width does not affect the result.
if (stride === width) {
- let pixelMap = await image.createPixelMap(component.byteBuffer, {
+ let pixelMap: image.PixelMap | undefined = await image.createPixelMap(component.byteBuffer, {
size: { height: height, width: width },
srcPixelFormat: image.PixelMapFormat.NV21,
})
@@ -73,18 +73,18 @@ class CameraService {
// Positive example: Case 2.When width and stride are not equal,
// At this time, the camera returned preview stream data component.byteBuffer to remove stride,
// copy the new dstArr data, data processing to other do not support stride interface processing.
- const dstBufferSize = width * height *
+ const dstBufferSize: number = width * height *
1.5; // Create a dstBufferSize space of width * height * 1.5. This is NV21 data format.
- const dstArr = new Uint8Array(dstBufferSize); // Store the buffer after the stride is removed.
+ const dstArr: Uint8Array = new Uint8Array(dstBufferSize); // Store the buffer after the stride is removed.
// For each line of data read, the camera supports an even width and height profile, which does not involve rounding.
for (let j = 0; j < height * 1.5; j++) { // Loop each row of dstArr data.
// Copy the first width bytes of each line of data from component.byteBuffer into dstArr
// (remove invalid pixels and get exactly an eight-byte array space of width*height per line).
- const srcBuf = new Uint8Array(component.byteBuffer, j * stride,
+ const srcBuf: Uint8Array = new Uint8Array(component.byteBuffer, j * stride,
width); // The buffer returned by component.byteBuffer traverses each line, starting at the top, with width bytes cut off each line.
dstArr.set(srcBuf, j * width); // Store the width*height data in dstArr.
}
- let pixelMap = await image.createPixelMap(dstArr.buffer, {
+ let pixelMap: image.PixelMap | undefined = await image.createPixelMap(dstArr.buffer, {
// The processed dstArr array buffer creates pixelMap directly by width and height,
// and stores it in the global variable stridePixel and passes it to Image for display.
size: { height: height, width: width },
@@ -106,7 +106,7 @@ class CameraService {
if (previewProfiles.length < 1) {
return undefined;
}
- let index = previewProfiles.findIndex((previewProfile: camera.Profile) => {
+ let index: number = previewProfiles.findIndex((previewProfile: camera.Profile) => {
return previewProfile.size.width === this.previewProfileObj.size.width &&
previewProfile.size.height === this.previewProfileObj.size.height &&
previewProfile.format === this.previewProfileObj.format;
@@ -146,7 +146,7 @@ class CameraService {
return;
}
// Turn on the camera
- let isOpenSuccess = await this.cameraInputOpenFn(this.cameraInput);
+ let isOpenSuccess: boolean = await this.cameraInputOpenFn(this.cameraInput);
if (!isOpenSuccess) {
Logger.error(TAG, 'Failed to open the camera.');
return;
@@ -182,7 +182,7 @@ class CameraService {
}
}
- getPreviewRotation() {
+ getPreviewRotation(): void {
let previewRotation: camera.ImageRotation | undefined = camera.ImageRotation.ROTATION_0;
try {
previewRotation = this.previewOutput?.getPreviewRotation(previewRotation);
diff --git a/DealStrideSolution/entry/src/main/ets/utils/CameraServiceThree.ets b/DealStrideSolution/entry/src/main/ets/utils/CameraServiceThree.ets
index 939c998e4d591c3fb3710b638eb95b74579cfc1e..bc7745806a612123e1df3b6919fe50b3716bf7b3 100644
--- a/DealStrideSolution/entry/src/main/ets/utils/CameraServiceThree.ets
+++ b/DealStrideSolution/entry/src/main/ets/utils/CameraServiceThree.ets
@@ -53,9 +53,9 @@ class CameraService {
}
if (nextImage) {
nextImage.getComponent(image.ComponentType.JPEG, async (_err, component: image.Component) => {
- let width = 1080; // Application create preview stream resolution corresponding to the width
- let height = 1080; // Application create preview stream resolution corresponding to the height
- let pixelMap = await image.createPixelMap(component.byteBuffer, {
+ let width: number = 1080; // Application create preview stream resolution corresponding to the width
+ let height: number = 1080; // Application create preview stream resolution corresponding to the height
+ let pixelMap: image.PixelMap | undefined = await image.createPixelMap(component.byteBuffer, {
size: {
height: height,
width: width
@@ -74,11 +74,11 @@ class CameraService {
}
// [End onImageArrival_start]
getPreviewProfile(cameraOutputCapability: camera.CameraOutputCapability): camera.Profile | undefined {
- let previewProfiles = cameraOutputCapability.previewProfiles;
+ let previewProfiles: Array = cameraOutputCapability.previewProfiles;
if (previewProfiles.length < 1) {
return undefined;
}
- let index = previewProfiles.findIndex((previewProfile: camera.Profile) => {
+ let index: number = previewProfiles.findIndex((previewProfile: camera.Profile) => {
return previewProfile.size.width === this.previewProfileObj.size.width &&
previewProfile.size.height === this.previewProfileObj.size.height &&
previewProfile.format === this.previewProfileObj.format;
@@ -118,7 +118,7 @@ class CameraService {
return;
}
// Turn on the camera
- let isOpenSuccess = await this.cameraInputOpenFn(this.cameraInput);
+ let isOpenSuccess: boolean = await this.cameraInputOpenFn(this.cameraInput);
if (!isOpenSuccess) {
Logger.error(TAG, 'Failed to open the camera.');
return;
@@ -154,7 +154,7 @@ class CameraService {
}
}
- getPreviewRotation() {
+ getPreviewRotation(): void {
let previewRotation: camera.ImageRotation | undefined = camera.ImageRotation.ROTATION_0;
try {
previewRotation = this.previewOutput?.getPreviewRotation(previewRotation);
@@ -265,7 +265,7 @@ class CameraService {
* Turn on the camera
*/
async cameraInputOpenFn(cameraInput: camera.CameraInput): Promise {
- let isOpenSuccess = false;
+ let isOpenSuccess: boolean = false;
try {
await cameraInput.open();
isOpenSuccess = true;
diff --git a/DealStrideSolution/entry/src/main/ets/utils/CameraServiceTwo.ets b/DealStrideSolution/entry/src/main/ets/utils/CameraServiceTwo.ets
index 13434fa10e884b79eb33a30a0599223ae1d11f41..1e92ea260692ef0b1a8a9c255b0574281ae2373d 100644
--- a/DealStrideSolution/entry/src/main/ets/utils/CameraServiceTwo.ets
+++ b/DealStrideSolution/entry/src/main/ets/utils/CameraServiceTwo.ets
@@ -57,19 +57,19 @@ class CameraService {
// [EndExclude Case2_start]
if (nextImage) {
nextImage.getComponent(image.ComponentType.JPEG, async (_err, component: image.Component) => {
- let width = 1080; // Application create preview stream resolution corresponding to the width
- let height = 1080; // Application create preview stream resolution corresponding to the height
- let stride = component.rowStride; // Get stride by using component.rowStride
+ let width: number = 1080; // Application create preview stream resolution corresponding to the width
+ let height: number = 1080; // Application create preview stream resolution corresponding to the height
+ let stride: number = component.rowStride; // Get stride by using component.rowStride
Logger.info(TAG, `receiver getComponent width:${width} height:${height} stride:${stride}`);
// stride and width are equal. Reading buffer by width does not affect the result
if (stride === width) {
- let pixelMap = await image.createPixelMap(component.byteBuffer, {
+ let pixelMap: image.PixelMap | undefined = await image.createPixelMap(component.byteBuffer, {
size: { height: height, width: width },
srcPixelFormat: image.PixelMapFormat.NV21,
})
AppStorage.setOrCreate('stridePixel', pixelMap);
} else {
- let pixelMap = await image.createPixelMap(component.byteBuffer, {
+ let pixelMap: image.PixelMap | undefined = await image.createPixelMap(component.byteBuffer, {
// Positive example: 1. width transmission stride when creating PixelMap.
size: { height: height, width: stride },
srcPixelFormat: 8,
@@ -85,7 +85,7 @@ class CameraService {
await pixelBefore?.release();
AppStorage.setOrCreate('stridePixel', pixelMap);
} catch (error) {
- let err = error as BusinessError;
+ let err: BusinessError = error as BusinessError;
hilog.warn(0x000, 'testTag', `setColorMode failed, code=${err.code}, message=${err.message}`);
}
}
@@ -99,11 +99,11 @@ class CameraService {
// [End Case2_start]
getPreviewProfile(cameraOutputCapability: camera.CameraOutputCapability): camera.Profile | undefined {
- let previewProfiles = cameraOutputCapability.previewProfiles;
+ let previewProfiles: Array = cameraOutputCapability.previewProfiles;
if (previewProfiles.length < 1) {
return undefined;
}
- let index = previewProfiles.findIndex((previewProfile: camera.Profile) => {
+ let index: number = previewProfiles.findIndex((previewProfile: camera.Profile) => {
return previewProfile.size.width === this.previewProfileObj.size.width &&
previewProfile.size.height === this.previewProfileObj.size.height &&
previewProfile.format === this.previewProfileObj.format;
@@ -143,7 +143,7 @@ class CameraService {
return;
}
// Turn on the camera
- let isOpenSuccess = await this.cameraInputOpenFn(this.cameraInput);
+ let isOpenSuccess: boolean = await this.cameraInputOpenFn(this.cameraInput);
if (!isOpenSuccess) {
Logger.error(TAG, 'Failed to open the camera.');
return;
@@ -290,7 +290,7 @@ class CameraService {
* Turn on the camera
*/
async cameraInputOpenFn(cameraInput: camera.CameraInput): Promise {
- let isOpenSuccess = false;
+ let isOpenSuccess: boolean = false;
try {
await cameraInput.open();
isOpenSuccess = true;
diff --git a/DealStrideSolution/entry/src/main/ets/utils/Logger.ets b/DealStrideSolution/entry/src/main/ets/utils/Logger.ets
index 9e7ae52b27eb0a3070f7946c57d0ce84540d29cd..bd50b48d92baf5cea809ac4aa91a8d0c87ecb2f4 100644
--- a/DealStrideSolution/entry/src/main/ets/utils/Logger.ets
+++ b/DealStrideSolution/entry/src/main/ets/utils/Logger.ets
@@ -15,7 +15,7 @@
import { hilog } from '@kit.PerformanceAnalysisKit';
-const TAG = 'DealStrideSolution';
+const TAG: string = 'DealStrideSolution';
class Logger {
private domain: number;
diff --git a/SegmentedPhotograph/README.md b/SegmentedPhotograph/README.md
index 9d0a4c6e0e74d6dcb37035319204f408715c7333..b319c92d8ffb80da8b234c3ca1e6f36e47204e3b 100644
--- a/SegmentedPhotograph/README.md
+++ b/SegmentedPhotograph/README.md
@@ -19,10 +19,14 @@
### 工程目录
```
├──entry/src/main/ets
+│ ├──common
+│ │ ├───utils
+│ │ │ ├───DateTimeUtil.ets // 时间处理公共方法
+│ │ │ ├───GlobalContext.ets // 全局上下文
+│ │ │ └───Logger.ets // 日志工具类
+│ │ └──Constants.ets // 视图层-拍照页面
│ ├──entryability
│ │ └──EntryAbility.ets // Ability的生命周期回调内容
-│ ├──entrybackupability
-│ │ └──EntryBackupAbility.ets // 程序入口类
│ ├──mode
│ │ └──CameraService.ets // 模型层- 相机服务
│ ├──pages
@@ -63,15 +67,15 @@
```
2. initCamera函数完成一个相机生命周期初始化的过程。
-- 首先通过[getCameraManager](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-camera#cameragetcameramanager)来获取CameraMananger相机管理器类。
-- 调用[getSupportedCameras](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-camera#getsupportedcameras)和[getSupportedOutputCapability](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-camera#getsupportedoutputcapability11)方法来获取支持的camera设备以及设备能力集。
-- 调用[createPreviewOutput](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-camera#createpreviewoutput)和[createPhotoOutput](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-camera#createphotooutput11)方法来创建预览输出和拍照输出对象。
+- 首先通过[getCameraManager](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-camera-f#cameragetcameramanager)来获取CameraMananger相机管理器类。
+- 调用[getSupportedCameras](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-camera-cameramanager#getsupportedcameras)和[getSupportedOutputCapability](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-camera-cameramanager#getsupportedoutputcapability11)方法来获取支持的camera设备以及设备能力集。
+- 调用[createPreviewOutput](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-camera-cameramanager#createpreviewoutput)和[createPhotoOutput](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-camera-cameramanager#createphotooutput11)方法来创建预览输出和拍照输出对象。
- 使用CameraInput的open方法来打开相机输入,通过onCameraStatusChange函数来创建CameraManager注册回调。
- 最后调用sessionFlowFn函数创建并开启Session。
-3. 确定拍照输出流。通过[CameraOutputCapability](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-camera#cameraoutputcapability)类中的photoProfiles属性,可获取当前设备支持的拍照输出流,通过cameraManager.createPhotoOutput方法创建拍照输出流。
+3. 确定拍照输出流。通过[CameraOutputCapability](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-camera-i#cameraoutputcapability)类中的photoProfiles属性,可获取当前设备支持的拍照输出流,通过cameraManager.createPhotoOutput方法创建拍照输出流。
-4. 触发拍照。通过photoOutput类的[capture](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-camera#capture-2)方法,执行拍照任务。
+4. 触发拍照。通过photoOutput类的[capture](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-camera-photooutput#capture)方法,执行拍照任务。
```typescript
async takePicture(): Promise {