提交 b60efb58 编写于 作者: S sqwlly

Merge branch 'monthly_20230815' of gitee.com:openharmony/docs into monthly_20230815

...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
- 相机最佳实践 - 相机最佳实践
- [拍照实现方案](camera-shooting-case.md) - [拍照实现方案](camera-shooting-case.md)
- [录像实现方案](camera-recording-case.md) - [录像实现方案](camera-recording-case.md)
- [人像模式拍照实现方案](camera-mode.md)
- [性能提升方案(仅对系统应用开放)](camera-performance-improvement.md) - [性能提升方案(仅对系统应用开放)](camera-performance-improvement.md)
- 图片 - 图片
- [图片开发概述](image-overview.md) - [图片开发概述](image-overview.md)
......
# 人像模式拍照实现方案
## 开发流程
人像模式依赖于模式化管理器,在获取到模式化管理的能力后,开始创建拍照流
模式化管理是对于cameraManager功能的增强与扩充,主要用于一些高级功能的管理,开发流程如下
![portraitgraphing Development Process](figures/portrait-capture-development-process.png)
## 完整示例
```ts
import camera from '@ohos.multimedia.camera'
import image from '@ohos.multimedia.image'
import media from '@ohos.multimedia.media'
// 创建CameraManager对象
context: any = getContext(this)
let cameraManager = camera.getCameraManager(this.context)
if (!cameraManager) {
console.error("camera.getCameraManager error")
return;
}
// 创建ModeManager对象
context: any = getContext(this)
let modeManager = camera.getModeManager(this.context)
if (!cameraManager) {
console.error("camera.getModeManager error")
return;
}
// 监听相机状态变化
cameraManager.on('cameraStatus', (err, cameraStatusInfo) => {
console.info(`camera : ${cameraStatusInfo.camera.cameraId}`);
console.info(`status: ${cameraStatusInfo.status}`);
})
// 获取相机列表
let cameraArray = cameraManager.getSupportedCameras();
if (cameraArray.length <= 0) {
console.error("cameraManager.getSupportedCameras error")
return;
}
for (let index = 0; index < cameraArray.length; index++) {
console.info('cameraId : ' + cameraArray[index].cameraId); // 获取相机ID
console.info('cameraPosition : ' + cameraArray[index].cameraPosition); // 获取相机位置
console.info('cameraType : ' + cameraArray[index].cameraType); // 获取相机类型
console.info('connectionType : ' + cameraArray[index].connectionType); // 获取相机连接类型
}
// 获取模式列表
let cameraModeArray = modeManager.getSupportedModes(cameraArray[0]);
if (cameraModeArray.length <= 0) {
console.error("modeManager.getSupportedModes error")
return;
}
// 创建相机输入流
let cameraInput
try {
cameraInput = cameraManager.createCameraInput(cameraArray[0]);
} catch (error) {
console.error('Failed to createCameraInput errorCode = ' + error.code);
}
// 监听cameraInput错误信息
let cameraDevice = cameraArray[0];
cameraInput.on('error', cameraDevice, (error) => {
console.info(`Camera input error code: ${error.code}`);
})
// 打开相机
await cameraInput.open();
// 获取当前模式相机设备支持的输出流能力
let cameraOutputCap = modeManager.getSupportedOutputCapability(cameraArray[0], cameraModeArray[0]);
if (!cameraOutputCap) {
console.error("modeManager.getSupportedOutputCapability error")
return;
}
console.info("outputCapability: " + JSON.stringify(cameraOutputCap));
let previewProfilesArray = cameraOutputCap.previewProfiles;
if (!previewProfilesArray) {
console.error("createOutput previewProfilesArray == null || undefined")
}
let photoProfilesArray = cameraOutputCap.photoProfiles;
if (!photoProfilesArray) {
console.error("createOutput photoProfilesArray == null || undefined")
}
// 创建预览输出流,其中参数 surfaceId 参考上文 XComponent 组件,预览流为XComponent组件提供的surface
let previewOutput
try {
previewOutput = cameraManager.createPreviewOutput(previewProfilesArray[0], surfaceId)
} catch (error) {
console.error("Failed to create the PreviewOutput instance.")
}
// 监听预览输出错误信息
previewOutput.on('error', (error) => {
console.info(`Preview output error code: ${error.code}`);
})
// 创建ImageReceiver对象,并设置照片参数:分辨率大小是根据前面 photoProfilesArray 获取的当前设备所支持的拍照分辨率大小去设置
let imageReceiver = await image.createImageReceiver(1920, 1080, 4, 8)
// 获取照片显示SurfaceId
let photoSurfaceId = await imageReceiver.getReceivingSurfaceId()
// 创建拍照输出流
let photoOutput
try {
photoOutput = cameraManager.createPhotoOutput(photoProfilesArray[0], photoSurfaceId)
} catch (error) {
console.error('Failed to createPhotoOutput errorCode = ' + error.code);
}
//创建portrait会话
let portraitSession
try {
portraitSession = modeManager.createCaptureSession(cameraModeArray[0])
} catch (error) {
console.error('Failed to create the CaptureSession instance. errorCode = ' + error.code);
}
// 监听portraitSession错误信息
portraitSession.on('error', (error) => {
console.info(`Capture session error code: ${error.code}`);
})
// 开始配置会话
try {
portraitSession.beginConfig()
} catch (error) {
console.error('Failed to beginConfig. errorCode = ' + error.code);
}
// 向会话中添加相机输入流
try {
portraitSession.addInput(cameraInput)
} catch (error) {
console.error('Failed to addInput. errorCode = ' + error.code);
}
// 向会话中添加预览输出流
try {
portraitSession.addOutput(previewOutput)
} catch (error) {
console.error('Failed to addOutput(previewOutput). errorCode = ' + error.code);
}
// 向会话中添加拍照输出流
try {
portraitSession.addOutput(photoOutput)
} catch (error) {
console.error('Failed to addOutput(photoOutput). errorCode = ' + error.code);
}
// 提交会话配置
await portraitSession.commitConfig()
// 启动会话
await portraitSession.start().then(() => {
console.info('Promise returned to indicate the session start success.');
})
// 获取支持的美颜类型
let beautyTypes
try {
beautyTypes = portraitSession.getSupportedBeautyTypes()
} catch (error) {
console.error('Failed to get the beauty types. errorCode = ' + error.code);
}
// 获取支持的美颜类型对应的美颜强度范围
let beautyRanges
try {
beautyRanges = portraitSession.getSupportedBeautyRanges(beautyTypes[0])
} catch (error) {
console.error('Failed to get the beauty types ranges. errorCode = ' + error.code);
}
// 设置美颜类型及对应的美颜强度
try {
portraitSession.setBeauty(beautyTypes[0], beautyRanges[0])
} catch (error) {
console.error('Failed to set the beauty type value. errorCode = ' + error.code);
}
// 获取已经设置的美颜类型对应的美颜强度
let beautyLevel
try {
beautyLevel = portraitSession.getBeauty(beautyTypes[0])
} catch (error) {
console.error('Failed to get the beauty type value. errorCode = ' + error.code);
}
// 获取支持的滤镜类型
let filterTypes
try {
filterTypes = portraitSession.getSupportedFilters()
} catch (error) {
console.error('Failed to get the filter types. errorCode = ' + error.code);
}
// 设置滤镜类型
try {
portraitSession.setFilter(filterTypes[0])
} catch (error) {
console.error('Failed to set the filter type value. errorCode = ' + error.code);
}
// 获取已经设置的滤镜类型
let filter
try {
filter = portraitSession.getFilter()
} catch (error) {
console.error('Failed to get the filter type value. errorCode = ' + error.code);
}
// 获取支持的虚化类型
let portraitTypes
try {
portraitTypes = portraitSession.getSupportedPortraitEffects()
} catch (error) {
console.error('Failed to get the portrait effects types. errorCode = ' + error.code);
}
// 设置虚化类型
try {
portraitSession.setPortraitEffect(portraitTypes[0])
} catch (error) {
console.error('Failed to set the portrait effects value. errorCode = ' + error.code);
}
// 获取已经设置的虚化类型
let effect
try {
effect = portraitSession.getPortraitEffect()
} catch (error) {
console.error('Failed to get the portrait effects value. errorCode = ' + error.code);
}
// 使用当前拍照设置进行拍照
photoOutput.capture(settings, async (err) => {
if (err) {
console.error('Failed to capture the photo ${err.message}');
return;
}
console.info('Callback invoked to indicate the photo capture request success.');
});
// 停止当前会话
portraitSession.stop()
// 释放相机输入流
cameraInput.close()
// 释放预览输出流
previewOutput.release()
// 释放拍照输出流
photoOutput.release()
// 释放会话
portraitSession.release()
// 会话置空
portraitSession = null
```
...@@ -23,9 +23,6 @@ ...@@ -23,9 +23,6 @@
- HSP - HSP
- [应用内HSP开发指导](in-app-hsp.md) - [应用内HSP开发指导](in-app-hsp.md)
- [应用间HSP开发指导](cross-app-hsp.md) - [应用间HSP开发指导](cross-app-hsp.md)
- 原子化服务
- [原子化服务开发指导](atomicService.md)
- [原子化服务空间管理(仅对系统应用开放)](atomicService-aging.md)
- 应用程序包快速修复 - 应用程序包快速修复
- [快速修复概述](quickfix-principles.md) - [快速修复概述](quickfix-principles.md)
- [快速修复命令行调试开发指导](quickfix-debug.md) - [快速修复命令行调试开发指导](quickfix-debug.md)
......
...@@ -131,14 +131,14 @@ struct ParentComponent { ...@@ -131,14 +131,14 @@ struct ParentComponent {
``` ```
- \@Recycle:\@Recycle装饰的自定义组件具备可复用能力 - \@Reusable:\@Reusable装饰的自定义组件具备可复用能力
> **说明:** > **说明:**
> >
> 从API version 10开始,该装饰器支持在ArkTS卡片中使用。 > 从API version 10开始,该装饰器支持在ArkTS卡片中使用。
```ts ```ts
@Recycle @Reusable
@Component @Component
struct MyComponent { struct MyComponent {
} }
......
...@@ -36,7 +36,7 @@ LocalStorage根据与\@Component装饰的组件的同步类型不同,提供了 ...@@ -36,7 +36,7 @@ LocalStorage根据与\@Component装饰的组件的同步类型不同,提供了
## 限制条件 ## 限制条件
- LocalStorage创建后,命名属性的类型不可更改。后续调用Set时必须使用相同类型的值。 - LocalStorage创建后,命名属性的类型不可更改。后续调用Set时必须使用相同类型的值。
- LocalStorage是页面级存储,[GetShared](../reference/arkui-ts/ts-state-management.md#getshared10)接口仅能获取当前stage,通过[windowStage.loadContent](../reference/apis/js-apis-window.md#loadcontent9)传入的LocalStorage实例,否则返回undefined。例子可见[将LocalStorage实例从UIAbility共享到一个或多个视图](#将localstorage实例从uiability共享到一个或多个视图) - LocalStorage是页面级存储,[GetShared](../reference/arkui-ts/ts-state-management.md#getshared10)接口仅能获取当前Stage通过[windowStage.loadContent](../reference/apis/js-apis-window.md#loadcontent9)传入的LocalStorage实例,否则返回undefined。例子可见[将LocalStorage实例从UIAbility共享到一个或多个视图](#将localstorage实例从uiability共享到一个或多个视图)
## \@LocalStorageProp ## \@LocalStorageProp
...@@ -402,7 +402,7 @@ export default class EntryAbility extends UIAbility { ...@@ -402,7 +402,7 @@ export default class EntryAbility extends UIAbility {
```ts ```ts
// 通过GetShared接口获取stage共享的Storage实例 // 通过GetShared接口获取stage共享的LocalStorage实例
let storage = LocalStorage.GetShared() let storage = LocalStorage.GetShared()
@Entry(storage) @Entry(storage)
......
...@@ -162,6 +162,26 @@ class ClassB { ...@@ -162,6 +162,26 @@ class ClassB {
this.a = a; this.a = a;
} }
} }
@Observed
class ClassD {
public c: ClassC;
constructor(c: ClassC) {
this.c = c;
}
}
@Observed
class ClassC extends ClassA {
public k: number;
constructor(k: number) {
// 调用父类方法对k进行处理
super(k);
this.k = k;
}
}
``` ```
...@@ -169,60 +189,64 @@ class ClassB { ...@@ -169,60 +189,64 @@ class ClassB {
```ts ```ts
@Component @Component
struct ViewA { struct ViewC {
label: string = 'ViewA1'; label: string = 'ViewC1';
@ObjectLink a: ClassA; @ObjectLink c: ClassC;
build() { build() {
Row() { Row() {
Button(`ViewA [${this.label}] this.a.c=${this.a.c} +1`) Column() {
Text(`ViewC [${this.label}] this.a.c = ${this.c.c}`)
.fontColor('#ffffffff')
.backgroundColor('#ff3fc4c4')
.height(50)
.borderRadius(25)
Button(`ViewC: this.c.c add 1`)
.backgroundColor('#ff7fcf58')
.onClick(() => { .onClick(() => {
this.a.c += 1; this.c.c += 1;
console.log('this.c.c:' + this.c.c)
}) })
} }
.width(300)
} }
} }
}
@Entry @Entry
@Component @Component
struct ViewB { struct ViewB {
@State b: ClassB = new ClassB(new ClassA(0)); @State b: ClassB = new ClassB(new ClassA(0));
@State child : ClassD = new ClassD(new ClassC(0));
build() { build() {
Column() { Column() {
ViewA({ label: 'ViewA #1', a: this.b.a }) ViewC({ label: 'ViewC #3', c: this.child.c})
ViewA({ label: 'ViewA #2', a: this.b.a }) Button(`ViewC: this.child.c.c add 10`)
.backgroundColor('#ff7fcf58')
Button(`ViewB: this.b.a.c+= 1`)
.onClick(() => {
this.b.a.c += 1;
})
Button(`ViewB: this.b.a = new ClassA(0)`)
.onClick(() => { .onClick(() => {
this.b.a = new ClassA(0); this.child.c.c += 10
}) console.log('this.child.c.c:' + this.child.c.c)
Button(`ViewB: this.b = new ClassB(ClassA(0))`)
.onClick(() => {
this.b = new ClassB(new ClassA(0));
}) })
} }
} }
} }
``` ```
被@Observed装饰的ClassC类,可以观测到继承基类的属性的变化。
ViewB中的事件句柄: ViewB中的事件句柄:
- this.b.a = new ClassA(0) 和this.b = new ClassB(new ClassA(0)): 对\@State装饰的变量b和其属性的修改。 - this.child.c = new ClassA(0) 和this.b = new ClassB(new ClassA(0)): 对\@State装饰的变量b和其属性的修改。
- this.b.a.c = ... :该变化属于第二层的变化,[@State](arkts-state.md#观察变化)无法观察到第二层的变化,但是ClassA被\@Observed装饰,ClassA的属性c的变化可以被\@ObjectLink观察到。 - this.child.c.c = ... :该变化属于第二层的变化,[@State](arkts-state.md#观察变化)无法观察到第二层的变化,但是ClassA被\@Observed装饰,ClassA的属性c的变化可以被\@ObjectLink观察到。
ViewA中的事件句柄: ViewC中的事件句柄:
- this.a.c += 1:对\@ObjectLink变量a的修改,将触发Button组件的刷新。\@ObjectLink和\@Prop不同,\@ObjectLink不拷贝来自父组件的数据源,而是在本地构建了指向其数据源的引用。 - this.c.c += 1:对\@ObjectLink变量a的修改,将触发Button组件的刷新。\@ObjectLink和\@Prop不同,\@ObjectLink不拷贝来自父组件的数据源,而是在本地构建了指向其数据源的引用。
- \@ObjectLink变量是只读的,this.a = new ClassA(...)是不允许的,因为一旦赋值操作发生,指向数据源的引用将被重置,同步将被打断。 - \@ObjectLink变量是只读的,this.a = new ClassA(...)是不允许的,因为一旦赋值操作发生,指向数据源的引用将被重置,同步将被打断。
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
| 装饰器参数 | 无 | | 装饰器参数 | 无 |
| 同步类型 | 单向同步:对父组件状态变量值的修改,将同步给子组件\@Prop装饰的变量,子组件\@Prop变量的修改不会同步到父组件的状态变量上。嵌套类型的场景请参考[观察变化](#观察变化)。 | | 同步类型 | 单向同步:对父组件状态变量值的修改,将同步给子组件\@Prop装饰的变量,子组件\@Prop变量的修改不会同步到父组件的状态变量上。嵌套类型的场景请参考[观察变化](#观察变化)。 |
| 允许装饰的变量类型 | Object、class、string、number、boolean、enum类型,以及这些类型的数组。<br/>不支持any,不支持简单类型和复杂类型的联合类型,不允许使用undefined和null。<br/>支持Date类型。<br/>支持类型的场景请参考[观察变化](#观察变化)。<br/>必须指定类型。<br/>**说明** :<br/>不支持Length、ResourceStr、ResourceColor类型,Length,ResourceStr、ResourceColor为简单类型和复杂类型的联合类型。<br/>在父组件中,传递给\@Prop装饰的值不能为undefined或者null,反例如下所示。<br/>CompA&nbsp;({&nbsp;aProp:&nbsp;undefined&nbsp;})<br/>CompA&nbsp;({&nbsp;aProp:&nbsp;null&nbsp;})<br/>\@Prop和[数据源](arkts-state-management-overview.md#基本概念)类型需要相同,有以下三种情况:<br/>-&nbsp;\@Prop装饰的变量和\@State以及其他装饰器同步时双方的类型必须相同,示例请参考[父组件@State到子组件@Prop简单数据类型同步](#父组件state到子组件prop简单数据类型同步)。<br/>-&nbsp;\@Prop装饰的变量和\@State以及其他装饰器装饰的数组的项同步时 ,\@Prop的类型需要和\@State装饰的数组的数组项相同,比如\@Prop&nbsp;:&nbsp;T和\@State&nbsp;:&nbsp;Array&lt;T&gt;,示例请参考[父组件@State数组中的项到子组件@Prop简单数据类型同步](#父组件state数组项到子组件prop简单数据类型同步);<br/>-&nbsp;当父组件状态变量为Object或者class时,\@Prop装饰的变量和父组件状态变量的属性类型相同,示例请参考[从父组件中的@State类对象属性到@Prop简单类型的同步](#从父组件中的state类对象属性到prop简单类型的同步)。 | | 允许装饰的变量类型 | Object、class、string、number、boolean、enum类型,以及这些类型的数组。<br/>不支持any,不支持简单类型和复杂类型的联合类型,不允许使用undefined和null。<br/>支持Date类型。<br/>支持类型的场景请参考[观察变化](#观察变化)。<br/>必须指定类型。<br/>**说明** :<br/>不支持Length、ResourceStr、ResourceColor类型,Length,ResourceStr、ResourceColor为简单类型和复杂类型的联合类型。<br/>在父组件中,传递给\@Prop装饰的值不能为undefined或者null,反例如下所示。<br/>CompA&nbsp;({&nbsp;aProp:&nbsp;undefined&nbsp;})<br/>CompA&nbsp;({&nbsp;aProp:&nbsp;null&nbsp;})<br/>\@Prop和[数据源](arkts-state-management-overview.md#基本概念)类型需要相同,有以下三种情况:<br/>-&nbsp;\@Prop装饰的变量和\@State以及其他装饰器同步时双方的类型必须相同,示例请参考[父组件@State到子组件@Prop简单数据类型同步](#父组件state到子组件prop简单数据类型同步)。<br/>-&nbsp;\@Prop装饰的变量和\@State以及其他装饰器装饰的数组的项同步时 ,\@Prop的类型需要和\@State装饰的数组的数组项相同,比如\@Prop&nbsp;:&nbsp;T和\@State&nbsp;:&nbsp;Array&lt;T&gt;,示例请参考[父组件@State数组中的项到子组件@Prop简单数据类型同步](#父组件state数组项到子组件prop简单数据类型同步);<br/>-&nbsp;当父组件状态变量为Object或者class时,\@Prop装饰的变量和父组件状态变量的属性类型相同,示例请参考[从父组件中的@State类对象属性到@Prop简单类型的同步](#从父组件中的state类对象属性到prop简单类型的同步)。 |
| 嵌套传递层数 | 在组件复用场景,建议@Prop深度嵌套数据不要超过5层,嵌套太多会导致深拷贝占用的空间过大以及GarbageCollection(垃圾回收),引起性能问题,此时更建议使用[\@ObjectLink](arkts-observed-and-objectlink.md)。如果子组件的数据不想同步回父组件,建议采用@Reusable中的aboutToReuse,实现父组件向子组件传递数据,具体用例请参考[组件复用场景](arkts-state-management-best-practices.md)。 |
| 被装饰变量的初始值 | 允许本地初始化。 | | 被装饰变量的初始值 | 允许本地初始化。 |
...@@ -32,7 +33,7 @@ ...@@ -32,7 +33,7 @@
| 传递/访问 | 说明 | | 传递/访问 | 说明 |
| --------- | ---------------------------------------- | | --------- | ---------------------------------------- |
| 从父组件初始化 | 如果本地有初始化,则是可选的。没有的话,则必选,支持父组件中的常规变量、\@State、\@Link、\@Prop、\@Provide、\@Consume、\@ObjectLink、\@StorageLink、\@StorageProp、\@LocalStorageLink和\@LocalStorageProp去初始化子组件中的\@Prop变量。 | | 从父组件初始化 | 如果本地有初始化,则是可选的。没有的话,则必选,支持父组件中的常规变量(常规变量对@Prop赋值,只是数值的初始化,常规变量的变化不会触发UI刷新。只有状态变量才能触发UI刷新)\@State、\@Link、\@Prop、\@Provide、\@Consume、\@ObjectLink、\@StorageLink、\@StorageProp、\@LocalStorageLink和\@LocalStorageProp去初始化子组件中的\@Prop变量。 |
| 用于初始化子组件 | \@Prop支持去初始化子组件中的常规变量、\@State、\@Link、\@Prop、\@Provide。 | | 用于初始化子组件 | \@Prop支持去初始化子组件中的常规变量、\@State、\@Link、\@Prop、\@Provide。 |
| 是否支持组件外访问 | \@Prop装饰的变量是私有的,只能在组件内访问。 | | 是否支持组件外访问 | \@Prop装饰的变量是私有的,只能在组件内访问。 |
...@@ -50,7 +51,7 @@ ...@@ -50,7 +51,7 @@
\@Prop装饰的数据可以观察到以下变化。 \@Prop装饰的数据可以观察到以下变化。
- 当装饰的类型是允许的类型,即Object、class、string、number、boolean、enum类型都可以观察到的赋值变化。 - 当装饰的类型是允许的类型,即Object、class、string、number、boolean、enum类型都可以观察到赋值的变化。
```ts ```ts
// 简单类型 // 简单类型
...@@ -88,29 +89,7 @@ this.title.value = 'Hi' ...@@ -88,29 +89,7 @@ this.title.value = 'Hi'
this.title.a.value = 'ArkUi' this.title.a.value = 'ArkUi'
``` ```
对于嵌套场景,如果装饰的class是被\@Observed装饰的,可以观察到class属性的变化。 对于嵌套场景,如果class是被\@Observed装饰的,可以观察到class属性的变化,示例请参考[@Prop嵌套场景](#@Prop嵌套场景)
```
@Observed
class ClassA {
public value: string;
constructor(value: string) {
this.value = value;
}
}
class Model {
public value: string;
public a: ClassA;
constructor(value: string, a: ClassA) {
this.value = value;
this.a = a;
}
}
@Prop title: Model;
// 可以观察到第一层的变化
this.title.value = 'Hi'
// 可以观察到ClassA属性的变化,因为ClassA被@Observed装饰this.title.a.value = 'ArkUi'
```
当装饰的类型是数组的时候,可以观察到数组本身的赋值、添加、删除和更新。 当装饰的类型是数组的时候,可以观察到数组本身的赋值、添加、删除和更新。
...@@ -568,4 +547,88 @@ struct MainProgram { ...@@ -568,4 +547,88 @@ struct MainProgram {
} }
} }
``` ```
### \@Prop嵌套场景
在嵌套场景下,每一层都要用@Observed装饰,且每一层都要被@Prop接收,这样才能观察到嵌套场景。
```ts
// 以下是嵌套类对象的数据结构。
@Observed
class ClassA {
public title: string;
constructor(title: string) {
this.title = title;
}
}
@Observed
class ClassB {
public name: string;
public a: ClassA;
constructor(name: string, a: ClassA) {
this.name = name;
this.a = a;
}
}
```
以下组件层次结构呈现的是@Prop嵌套场景的数据结构。
```ts
@Entry
@Component
struct Parent {
@State votes: ClassB = new ClassB('Hello', new ClassA('world'))
build() {
Column() {
Button('change')
.onClick(() => {
this.votes.name = "aaaaa"
this.votes.a.title = "wwwww"
})
Child({ vote: this.votes })
}
}
}
@Component
struct Child {
@Prop vote: ClassB
build() {
Column() {
Text(this.vote.name).fontSize(36).fontColor(Color.Red).margin(50)
.onClick(() => {
this.vote.name = 'Bye'
})
Text(this.vote.a.title).fontSize(36).fontColor(Color.Blue)
.onClick(() => {
this.vote.a.title = "openHarmony"
})
Child1({vote1:this.vote.a})
}
}
}
@Component
struct Child1 {
@Prop vote1: ClassA
build() {
Column() {
Text(this.vote1.title).fontSize(36).fontColor(Color.Red).margin(50)
.onClick(() => {
this.vote1.title = 'Bye Bye'
})
}
}
}
```
<!--no_check--> <!--no_check-->
\ No newline at end of file
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
| \@Provide传递/访问 | 说明 | | \@Provide传递/访问 | 说明 |
| -------------- | ---------------------------------------- | | -------------- | ---------------------------------------- |
| 从父组件初始化和更新 | 可选,允许父组件中常规变量、\@State、\@Link、\@Prop、\@Provide、\@Consume、\@ObjectLink、\@StorageLink、\@StorageProp、\@LocalStorageLink和\@LocalStorageProp装饰的变量装饰变量初始化子组件\@Provide。 | | 从父组件初始化和更新 | 可选,允许父组件中常规变量(常规变量对@Prop赋值,只是数值的初始化,常规变量的变化不会触发UI刷新,只有状态变量才能触发UI刷新)\@State、\@Link、\@Prop、\@Provide、\@Consume、\@ObjectLink、\@StorageLink、\@StorageProp、\@LocalStorageLink和\@LocalStorageProp装饰的变量装饰变量初始化子组件\@Provide。 |
| 用于初始化子组件 | 允许,可用于初始化\@State、\@Link、\@Prop、\@Provide。 | | 用于初始化子组件 | 允许,可用于初始化\@State、\@Link、\@Prop、\@Provide。 |
| 和父组件同步 | 否。 | | 和父组件同步 | 否。 |
| 和后代组件同步 | 和\@Consume双向同步。 | | 和后代组件同步 | 和\@Consume双向同步。 |
......
...@@ -1023,3 +1023,344 @@ struct CompA { ...@@ -1023,3 +1023,344 @@ struct CompA {
} }
} }
``` ```
## 组件复用场景
子组件通过@Prop接收父组件传递的数据,如果嵌套的层数过多,会导致深拷贝占用的空间过大以及GarbageCollection(垃圾回收),引起性能问题。下面给出5层@Prop嵌套传递数据的不推荐用法及通过@Reusable实现父组件向子组件传递数据的推荐用法。
### 不推荐用法
```ts
// 以下是嵌套类对象的数据结构。
@Observed
class ClassA {
public title: string;
constructor(title: string) {
this.title = title;
}
}
@Observed
class ClassB {
public name: string;
public a: ClassA;
constructor(name: string, a: ClassA) {
this.name = name;
this.a = a;
}
}
@Observed
class ClassC {
public name: string;
public b: ClassB;
constructor(name: string, b: ClassB) {
this.name = name;
this.b = b;
}
}
@Observed
class ClassD {
public name: string;
public c: ClassC;
constructor(name: string, c: ClassC) {
this.name = name;
this.c = c;
}
}
@Observed
class ClassE {
public name: string;
public d: ClassD;
constructor(name: string, d: ClassD) {
this.name = name;
this.d = d;
}
}
```
以下组件层次结构呈现的是@Prop嵌套场景的数据结构。
```ts
@Entry
@Component
struct Parent {
@State vote: ClassE = new ClassE('Hi', new ClassD('OpenHarmony', new ClassC('Hello', new ClassB('World', new ClassA('Peace')))))
build() {
Column() {
Button('change')
.onClick(() => {
this.vote.name = "Hello"
})
Child({ voteOne: this.vote })
}
}
}
@Component
struct Child {
@Prop voteOne: ClassE
build() {
Column() {
Text(this.voteOne.name).fontSize(24).fontColor(Color.Red).margin(50)
.onClick(() => {
console.log('this.voteOne.name:' + this.voteOne.name);
this.voteOne.name = 'Bye'
})
ChildOne({voteTwo:this.voteOne.d})
}
}
}
@Component
struct ChildOne {
@Prop voteTwo: ClassD
build() {
Column() {
Text(this.voteTwo.name).fontSize(24).fontColor(Color.Red).margin(50)
.onClick(() => {
console.log('this.voteTwo.name:' + this.voteTwo.name);
this.voteTwo.name = 'Bye Bye'
})
ChildTwo({voteThree:this.voteTwo.c})
}
}
}
@Component
struct ChildTwo {
@Prop voteThree: ClassC
build() {
Column() {
Text(this.voteThree.name).fontSize(24).fontColor(Color.Red).margin(50)
.onClick(() => {
console.log('this.voteThree.name:' + this.voteThree.name);
this.voteThree.name = 'Bye Bye Bye'
})
ChildThree({voteFour:this.voteThree.b})
}
}
}
@Component
struct ChildThree {
@Prop voteFour: ClassB
build() {
Column() {
Text(this.voteFour.name).fontSize(24).fontColor(Color.Red).margin(50)
.onClick(() => {
console.log('this.voteFour.name:' + this.voteFour.name);
this.voteFour.name = 'Bye Bye Bye Bye'
})
ChildFour({voteFive:this.voteFour.a})
}
}
}
@Component
struct ChildFour {
@Prop voteFive: ClassA
build() {
Column() {
Text(this.voteFive.title).fontSize(24).fontColor(Color.Red).margin(50)
.onClick(() => {
console.log('this.voteFive.title:' + this.voteFive.title);
this.voteFive.title = 'Bye Bye Bye Bye Bye'
})
}
}
}
```
### 推荐用法
当在组件复用场景时,父组件向子组件传递数据,子组件变化不会同步给父组件,推荐使用aboutToResue。
```ts
// 以下是嵌套类对象的数据结构。
@Observed
class ClassA {
public title: string;
constructor(title: string) {
this.title = title;
}
}
@Observed
class ClassB {
public name: string;
public a: ClassA;
constructor(name: string, a: ClassA) {
this.name = name;
this.a = a;
}
}
@Observed
class ClassC {
public name: string;
public b: ClassB;
constructor(name: string, b: ClassB) {
this.name = name;
this.b = b;
}
}
@Observed
class ClassD {
public name: string;
public c: ClassC;
constructor(name: string, c: ClassC) {
this.name = name;
this.c = c;
}
}
@Observed
class ClassE {
public name: string;
public d: ClassD;
constructor(name: string, d: ClassD) {
this.name = name;
this.d = d;
}
}
```
以下组件层次结构呈现的是@Reusable组件复用场景的数据结构。
```ts
@Entry
@Component
struct Parent {
@State vote: ClassE = new ClassE('Hi', new ClassD('OpenHarmony', new ClassC('Hello', new ClassB('World', new ClassA('Peace')))))
build() {
Column() {
Button('change')
.onClick(() => {
this.vote.name = "Hello"
})
.reuseId(Child.name)
Child({voteOne: this.vote})
}
}
}
@Reusable
@Component
struct Child {
@State voteOne: ClassE = new ClassE('voteOne', new ClassD('OpenHarmony', new ClassC('Hello', new ClassB('World', new ClassA('Peace')))))
aboutToReuse(params){
this.voteOne = params
}
build() {
Column() {
Text(this.voteOne.name).fontSize(24).fontColor(Color.Red).margin(50)
.onClick(() => {
console.error('this.voteOne.name:' + this.voteOne.name);
this.voteOne.name = 'Bye'
})
.reuseId(ChildOne.name)
ChildOne({voteTwo: this.voteOne.d})
}
}
}
@Reusable
@Component
struct ChildOne {
@State voteTwo: ClassD = new ClassD('voteTwo', new ClassC('Hello', new ClassB('World', new ClassA('Peace'))))
aboutToReuse(params){
this.voteTwo = params
}
build() {
Column() {
Text(this.voteTwo.name).fontSize(24).fontColor(Color.Red).margin(50)
.onClick(() => {
console.error('this.voteTwo.name:' + this.voteTwo.name);
this.voteTwo.name = 'Bye Bye'
})
.reuseId(ChildTwo.name)
ChildTwo({voteThree: this.voteTwo.c})
}
}
}
@Reusable
@Component
struct ChildTwo {
@State voteThree: ClassC = new ClassC('voteThree', new ClassB('World', new ClassA('Peace')))
aboutToReuse(params){
this.voteThree = params
}
build() {
Column() {
Text(this.voteThree.name).fontSize(24).fontColor(Color.Red).margin(50)
.onClick(() => {
console.log('this.voteThree.name:' + this.voteThree.name);
this.voteThree.name = 'Bye Bye Bye'
})
.reuseId(ChildThree.name)
ChildThree({voteFour: this.voteThree.b})
}
}
}
@Reusable
@Component
struct ChildThree {
@State voteFour: ClassB = new ClassB('voteFour', new ClassA('Peace'))
aboutToReuse(params){
this.voteFour = params
}
build() {
Column() {
Text(this.voteFour.name).fontSize(24).fontColor(Color.Red).margin(50)
.onClick(() => {
console.log('this.voteFour.name:' + this.voteFour.name);
this.voteFour.name = 'Bye Bye Bye Bye'
})
.reuseId(ChildFour.name)
ChildFour({voteFive: this.voteFour.a})
}
}
}
@Reusable
@Component
struct ChildFour {
@State voteFive: ClassA = new ClassA('voteFive')
aboutToReuse(params){
this.voteFive = params
}
build() {
Column() {
Text(this.voteFive.title).fontSize(24).fontColor(Color.Red).margin(50)
.onClick(() => {
console.log('this.voteFive.title:' + this.voteFive.title);
this.voteFive.title = 'Bye Bye Bye Bye Bye'
})
}
}
}
```
\ No newline at end of file
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
| 传递/访问 | 说明 | | 传递/访问 | 说明 |
| ------------------ | ------------------------------------------------------------ | | ------------------ | ------------------------------------------------------------ |
| 从父组件初始化 | 可选,从父组件初始化或者本地初始化。如果从父组件初始化将会覆盖本地初始化。<br/>支持父组件中常规变量、\@State、\@Link、\@Prop、\@Provide、\@Consume、\@ObjectLink、\@StorageLink、\@StorageProp、\@LocalStorageLink和\@LocalStorageProp装饰的变量,初始化子组件的\@State。 | | 从父组件初始化 | 可选,从父组件初始化或者本地初始化。如果从父组件初始化将会覆盖本地初始化。<br/>支持父组件中常规变量(常规变量对@Prop赋值,只是数值的初始化,常规变量的变化不会触发UI刷新,只有状态变量才能触发UI刷新)\@State、\@Link、\@Prop、\@Provide、\@Consume、\@ObjectLink、\@StorageLink、\@StorageProp、\@LocalStorageLink和\@LocalStorageProp装饰的变量,初始化子组件的\@State。 |
| 用于初始化子组件 | \@State装饰的变量支持初始化子组件的常规变量、\@State、\@Link、\@Prop、\@Provide。 | | 用于初始化子组件 | \@State装饰的变量支持初始化子组件的常规变量、\@State、\@Link、\@Prop、\@Provide。 |
| 是否支持组件外访问 | 不支持,只能在组件内访问。 | | 是否支持组件外访问 | 不支持,只能在组件内访问。 |
......
...@@ -4,27 +4,29 @@ HAR(Harmony Archive)是静态共享包,可以包含代码、C++库、资 ...@@ -4,27 +4,29 @@ HAR(Harmony Archive)是静态共享包,可以包含代码、C++库、资
## 创建HAR模块 ## 创建HAR模块
通过DevEco Studio创建一个HAR模块,创建方式可[参考](https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/creating_har_api9-0000001518082393-V3#section143510369612) 通过DevEco Studio创建一个HAR模块,创建方式可[参考](https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/creating_har_api9-0000001518082393-V3#section143510369612)
需要对代码资产进行保护时,建议开启混淆能力混淆能力开启后,DevEco Studio在构建HAR时,会对代码进行编译、混淆及压缩处理,保护代码资产。 需要对代码资产进行保护时,建议开启混淆能力混淆能力开启后,DevEco Studio在构建HAR时,会对代码进行编译、混淆及压缩处理,保护代码资产。
注意:仅Stage模型的ArkTS工程支持混淆。 > 注意:仅Stage模型的ArkTS工程支持混淆。
### 在API9中,HAR模块默认不开启混淆能力,开启混淆能力,需要把HAR模块的build-profile.json5文件中的artifactType字段设置为obfuscation,配置如下所示 混淆功能在不同版本默认开启情况不同
```json - 在API 9中,HAR模块默认不开启混淆能力,开启混淆能力,需要把HAR模块的build-profile.json5文件中的artifactType字段设置为obfuscation,配置如下所示:
{
```json
{
"apiType": "stageMode", "apiType": "stageMode",
"buildOption": { "buildOption": {
"artifactType": "obfuscation" "artifactType": "obfuscation"
} }
} }
``` ```
artifactType字段有以下两种取值,默认缺省为original。 artifactType字段有以下两种取值,默认缺省为original。
- original:不混淆。 - original:不混淆。
- obfuscation:混淆,目前仅支持uglify混淆。 - obfuscation:混淆,目前仅支持uglify混淆。
### 在API10中,HAR模块默认开启混淆能力,可以在HAR模块的build-profile.json5文件中的ruleOptions字段下的enable进行设置,配置如下所示: - 在API10中,HAR模块默认开启混淆能力,可以在HAR模块的build-profile.json5文件中的ruleOptions字段下的enable进行设置,配置如下所示:
```json ```json
{ {
"apiType": "stageMode", "apiType": "stageMode",
"buildOption": { "buildOption": {
}, },
...@@ -51,8 +53,8 @@ artifactType字段有以下两种取值,默认缺省为original。 ...@@ -51,8 +53,8 @@ artifactType字段有以下两种取值,默认缺省为original。
"name": "default" "name": "default"
} }
] ]
} }
``` ```
### 适配指导 ### 适配指导
该字段配置前向兼容,原有功能暂时不受影响。API10后续将逐步废弃,建议尽快用新的配置方式。 该字段配置前向兼容,原有功能暂时不受影响。API10后续将逐步废弃,建议尽快用新的配置方式。
......
...@@ -766,7 +766,7 @@ class Point { ...@@ -766,7 +766,7 @@ class Point {
x: number = 0 x: number = 0
y: number = 0 y: number = 0
} }
let p: Point = {42 ,42} let p: Point = {x: 42, y: 42}
``` ```
### 字段 ### 字段
...@@ -868,11 +868,11 @@ class Rectangle { ...@@ -868,11 +868,11 @@ class Rectangle {
} }
``` ```
实例方法需要在类的实例上调用 必须通过类的实例调用实例方法
```typescript ```typescript
let r = new Rectangle(10, 10) let square = new Rectangle(10, 10)
console.log(square.calculateArea()) // output: 100 console.log(square.calculateArea()) // 输出:100
``` ```
#### 静态方法 #### 静态方法
...@@ -883,7 +883,7 @@ console.log(square.calculateArea()) // output: 100 ...@@ -883,7 +883,7 @@ console.log(square.calculateArea()) // output: 100
所有实例都可以访问静态方法。 所有实例都可以访问静态方法。
要调用静态方法,需要使用类名 必须通过类名调用静态方法
```typescript ```typescript
class Cl { class Cl {
...@@ -1309,7 +1309,7 @@ class Stack<Element> { ...@@ -1309,7 +1309,7 @@ class Stack<Element> {
public pop(): Element { public pop(): Element {
// ... // ...
} }
public push(e: Element) { public push(e: Element):void {
// ... // ...
} }
} }
...@@ -1402,7 +1402,7 @@ foo<number>() ...@@ -1402,7 +1402,7 @@ foo<number>()
## 空安全 ## 空安全
默认情况下,ArkTS中的所有类型都是不可为空的,因此类型的值不能为空。这类似于TypeScript的严格空值检查模式(`strictNullChecks`),但规则更严格,而且ArkTS中没有`undefined`类型 默认情况下,ArkTS中的所有类型都是不可为空的,因此类型的值不能为空。这类似于TypeScript的严格空值检查模式(`strictNullChecks`),但规则更严格。
在下面的示例中,所有行都会导致编译时错误: 在下面的示例中,所有行都会导致编译时错误:
...@@ -1454,28 +1454,47 @@ class Person { ...@@ -1454,28 +1454,47 @@ class Person {
### 可选链 ### 可选链
可选链运算符`?.` 可以在编写代码时遇到求值为null的表达式就停止运行 在访问对象属性时,如果该属性是`undefined`或者`null`,可选链运算符会返回`undefined`
```typescript ```typescript
class Person { class Person {
// ... nick : string | null = null
spouse: Person | null = null spouse ?: Person
nick: string | null = null
getSpouseNick(): string | null { setSpouse(spouse: Person) : void {
this.spouse = spouse
}
getSpouseNick(): string | null | undefined {
return this.spouse?.nick return this.spouse?.nick
} }
constructor(nick: string) {
this.nick = nick
this.spouse = undefined
}
} }
``` ```
**说明**`getSpouseNick`的返回类型必须为`string | null`,因为该方法可能返回null **说明**`getSpouseNick`的返回类型必须为`string | null | undefined`,因为该方法可能返回`null`或者`undefined`
可选链可以是任何长度的,可包含任意数量的 `?.` 运算符。 可选链可以任意长,可以包含任意数量的`?.`运算符。
在以下示例中,如果某人有配偶,且配偶有昵称,则输出是该人的配偶昵称。否则,输出为空 在以下示例中,如果一个`Person`的实例有不为空的`spouse`属性,且`spouse`有不为空的`nickname`属性,则输出`spouse.nick`。否则,输出`undefined`
```typescript ```typescript
let p: Person = ... class Person {
console.log(p?.spouse?.nick) nick : string | null = null
spouse ?: Person
constructor(nick: string) {
this.nick = nick
this.spouse = undefined
}
}
let p: Person = new Person("Alice")
console.log(p.spouse?.nick) // 打印undefined
``` ```
## 模块 ## 模块
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
> **说明:** > **说明:**
> >
> 请使用**DevEco Studio V3.0.0.900 Beta3**及更高版本。
>
> 为确保运行效果,本文以使用**DevEco Studio 4.0 Beta2**版本为例,点击[此处](../../release-notes/OpenHarmony-v4.0-beta2.md#配套关系)获取下载链接。 > 为确保运行效果,本文以使用**DevEco Studio 4.0 Beta2**版本为例,点击[此处](../../release-notes/OpenHarmony-v4.0-beta2.md#配套关系)获取下载链接。
## 创建ArkTS工程 ## 创建ArkTS工程
......
...@@ -671,7 +671,7 @@ async function createTonePlayerBefore(){ ...@@ -671,7 +671,7 @@ async function createTonePlayerBefore(){
| ------------- | --------------------------- | ---- | ---------------- | | ------------- | --------------------------- | ---- | ---------------- |
| content | [ContentType](#contenttype) | 否 | 媒体类型。<br>API version 8、9为必填参数,从API version 10开始,变更为可选参数。 | | content | [ContentType](#contenttype) | 否 | 媒体类型。<br>API version 8、9为必填参数,从API version 10开始,变更为可选参数。 |
| usage | [StreamUsage](#streamusage) | 是 | 音频流使用类型。 | | usage | [StreamUsage](#streamusage) | 是 | 音频流使用类型。 |
| rendererFlags | number | 是 | 音频渲染器标志。 | | rendererFlags | number | 是 | 音频渲染器标志。<br>0代表普通音频渲染器,1代表低时延音频渲染器。js接口暂不支持低时延音频渲染器。 |
## InterruptResult<sup>9+</sup> ## InterruptResult<sup>9+</sup>
......
...@@ -44,6 +44,44 @@ getCameraManager(context: Context): CameraManager ...@@ -44,6 +44,44 @@ getCameraManager(context: Context): CameraManager
```js ```js
let cameraManager = camera.getCameraManager(context); let cameraManager = camera.getCameraManager(context);
``` ```
## camera.getModeManager
getModeManager(context: Context): ModeManager
获取模式化管理器实例,同步返回结果。
模式化管理是对于cameraManager功能的增强与扩充,主要用于一些高级功能的管理(如人像模式)。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ---- | ---------------------------- |
| context | [Context](js-apis-inner-app-context.md) | 是 | 应用上下文。 |
**返回值:**
| 类型 | 说明 |
| --------------------------------------| -----------|
| [ModeManager](#modemanager) | 模式化管理器。|
**错误码:**
以下错误码的详细介绍请参见[Camera错误码](../errorcodes/errorcode-camera.md)
| 错误码ID | 错误信息 |
| --------------- | --------------- |
| 7400101 | Parameter missing or parameter type incorrect |
| 7400201 | Camera service fatal error. |
**示例:**
```js
let modeManager = camera.getModeManager(context);
```
## CameraStatus ## CameraStatus
...@@ -122,6 +160,65 @@ let cameraManager = camera.getCameraManager(context); ...@@ -122,6 +160,65 @@ let cameraManager = camera.getCameraManager(context);
| DEVICE_PREEMPTED | 7400109 | 相机被抢占导致无法使用 | | DEVICE_PREEMPTED | 7400109 | 相机被抢占导致无法使用 |
| SERVICE_FATAL_ERROR | 7400201 | 相机服务错误返回。 | | SERVICE_FATAL_ERROR | 7400201 | 相机服务错误返回。 |
## CameraMode
相机模式。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ----------------| ---- | ---------|
| NORMAL | 0 | 普通模式 |
| CAPTURE | 1 | 拍照模式 |
| VIDEO | 2 | 录像模式 |
| PORTRAIT | 3 | 人像模式 |
| NIGHT | 4 | 夜景模式 |
| PROFESSIONAL | 5 | 专业模式 |
| SLOW_MOTION | 6 | 慢动作模式|
## FilterType
滤镜类型。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ----------------| ---- | ---------|
| NONE | 0 | 原图 |
| CLASSIC | 1 | 经典 |
| DAWN | 2 | 晨光 |
| PURE | 3 | 清纯 |
| GREY | 4 | 灰调 |
| NATURAL | 5 | 自然 |
| MORI | 6 | 森系 |
| FAIR | 7 | 白皙 |
| PINK | 8 | 粉调 |
## PortraitEffect
人像效果类型。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ----------------| ---- | ---------|
| OFF | 0 | 关闭 |
| CIRCLES | 1 | 圆形 |
## BeautyType
美颜类型。
**系统能力:** SystemCapability.Multimedia.Camera.Core
| 名称 | 值 | 说明 |
| ----------------| ---- | ---------|
| AUTO_TYPE | 0 | 自动 |
| SKIN_SMOOTH | 1 | 光滑 |
| FACE_SLENDER | 2 | 瘦脸 |
| SKIN_TONE | 3 | 肤色 |
## CameraManager ## CameraManager
相机管理器类,使用前需要通过getCameraManager获取相机管理实例。 相机管理器类,使用前需要通过getCameraManager获取相机管理实例。
...@@ -720,6 +817,104 @@ function getDeferredPreviewOutput(context: Context, previewProfile: camera.Profi ...@@ -720,6 +817,104 @@ function getDeferredPreviewOutput(context: Context, previewProfile: camera.Profi
const output: Promise<PreviewOutput> = cameraManager.createDeferredPreviewOutput(previewProfile); const output: Promise<PreviewOutput> = cameraManager.createDeferredPreviewOutput(previewProfile);
return output; return output;
} }
```
## ModeManager
相机模式化管理器类,使用前需要通过[getModeManager](#cameragetmodemanager)获取相机模式化管理实例。
### getSupportedModes
getSupportedModes(camera: CameraDevice): Array\<CameraMode\>
获取指定相机设备支持的模式列表,同步返回结果。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------- | ---- | ------------------- |
| camera | \<[CameraDevice](#cameradevice)> | 是 | 相机设备实例,通过[getSupportedCameras](#getsupportedcameras)接口获取。 |
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------- | ---------------------------- |
| Array\<[CameraMode](#cameramode)> | 支持的模式列表。 |
**示例:**
```js
let cameraModes = cameraManager.getSupportedModes(cameraDevices[0]);
```
### getSupportedOutputCapability
getSupportedOutputCapability(camera:CameraDevice, mode: CameraMode): CameraOutputCapability
获取指定模式下相机设备支持的输出能力,同步返回结果。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
| cameraDevice | [CameraDevice](#cameradevice) | 是 | 相机设备,通过[getSupportedCameras](#getsupportedcameras)接口获取。 |
| mode | [CameraMode](#cameramode) | 是 | 指定模式,通过[getSupportedModes](#getsupportedmodes)接口获取。 |
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------- | ---------------------------- |
| [CameraOutputCapability](#cameraoutputcapability) | 相机输出能力。 |
**示例:**
```js
let cameras = cameraManager.getSupportedCameras();
let cameraDevice = cameras[0];
let cameraModes = modeManager.getSupportedModes(cameraDevice);
let mode = cameraModes[0]
let cameraOutputCapability = modeManager.getSupportedOutputCapability(cameraDevice, mode);
```
### createCaptureSession
createCaptureSession(mode: CameraMode): CaptureSession
根据当前的模式名,创建指定模式的会话。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
| mode | [CameraMode](#cameramode) | 是 | 指定模式,通过[getSupportedModes](#getsupportedmodes)获取。 |
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------- | ---------------------------- |
| [CaptureSession](#capturesession) | 指定模式的会话实例。 |
**示例:**
```js
let cameras = cameraManager.getSupportedCameras();
let cameraDevice = cameras[0];
let cameraModes = modeManager.getSupportedModes(cameraDevice);
let mode = cameraModes[0]
let captureSession = modeManager.createCaptureSession(mode);
``` ```
## PrelaunchConfig ## PrelaunchConfig
...@@ -2418,6 +2613,187 @@ try { ...@@ -2418,6 +2613,187 @@ try {
console.log(error.code); console.log(error.code);
} }
``` ```
### getSupportedFilters
getSupportedFilters(): Array\<FilterType>
获取当前支持的滤镜效果列表。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------- | ----------------------------- |
| Array\<FilterType\> | 返回支持的滤镜效果列表。 |
**示例:**
```js
let FilterTypes = captureSession.getSupportedFilters();
```
### setFilter
setFilter(filter: FilterType): void
设置滤镜效果。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------| ---- | ---------------------|
| filter | [FilterType](#filtertype) | 是 | 当前用户设置的滤镜类型。 |
**示例:**
```js
let FilterTypes = captureSession.getSupportedFilters();
if (!FilterTypes.empty()) {
captureSession.setFilter(FilterTypes[0]);
}
```
### getFilter
getFilter(): number
获取当前已设置的滤镜效果。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------- | ----------------------------|
| [FilterType](#filtertype)| 已设置的滤镜效果。可查阅[FilterType](#filtertype)。|
**示例:**
```js
let FilterType = captureSession.getFilter();
```
### getSupportedBeautyTypes
getSupportedBeautyTypes(): Array<BeautyType>
获取当前支持的美颜效果列表。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------- | ----------------------------- |
| Array\<BeautyType\>| 返回当前支持的美颜效果列表。 |
**示例:**
```js
let FilterTypes = captureSession.getSupportedBeautyTypes();
```
### getSupportedBeautyRanges
getSupportedBeautyRanges(type: BeautyType): Array<number>
获取指定美颜效果的范围值。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------| ---- | ----------|
| type | [BeautyType](#beautytype) | 是 | 美颜类型。 |
**返回值:**
| 类型 | 说明 |
| ---------- | ----------------------------- |
| Array\<number\> | 当前美颜类型所支持的美颜强度。 |
**示例:**
```js
let beautyTypes = captureSession.getSupportedBeautyTypes();
if (!beautyTypes.empty()) {
let nums = captureSession.getSupportedBeautyRanges(beautyTypes[0]);
}
```
### setBeauty
setBeauty(type: BeautyType, value: number): void
设置美颜类型以及对应的美颜强度
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------| ---- | --------------------- |
| type | [BeautyType](#beautytype) | 是 | 美颜类型 |
| value | [number] | 是 | 美颜强度,通过[getSupportedBeautyRanges](#getsupportedbeautyranges)接口获取。|
**示例:**
```js
let beautyTypes = captureSession.getSupportedBeautyTypes();
let beautyLevels;
if (!beautyTypes.empty()) {
beautyLevels = captureSession.getSupportedBeautyRanges(beautyTypes[0]);
}
if (!beautyTypes.empty() && beautyLevels.empty()) {
captureSession.setBeauty(beautyTypes[0], beautyLevels[0]);
}
```
### getBeauty
getBeauty(type: BeautyType): number
查询当前已设置的美颜效果对应的美颜强度。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | --------------------- |
| type | [BeautyType](#beautytype) | 是 | 美颜类型 |
**返回值:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | --------------------- |
| value | [number] | 是 | 美颜强度 |
**示例:**
```js
let BeautyTypes = captureSession.getSupportedBeautyTypes();
let beautyLevels;
if (!BeautyTypes.empty()) {
beautyLevels = captureSession.getSupportedBeautyRanges(BeautyTypes[0]);
}
if (!BeautyTypes.empty() && beautyLevels.empty()) {
captureSession.setBeauty(BeautyTypes[0], beautyLevels[0]);
}
let beautyLevel = captureSession.getBeauty(BeautyTypes[0]);
```
### on('focusStateChange') ### on('focusStateChange')
...@@ -2464,6 +2840,80 @@ captureSession.on('error', (error) => { ...@@ -2464,6 +2840,80 @@ captureSession.on('error', (error) => {
console.log(`Capture session error code: ${error.code}`); console.log(`Capture session error code: ${error.code}`);
}) })
``` ```
## PortraitSession
继承自[CaptureSession](#capturesession),用于设置人像模式的参数。
### getSupportedPortraitEffects
getSupportedPortraitEffects(): Array<PortraitEffect>
获取支持的人像虚化效果列表。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------- | ---------------------------- |
| Array<[PortraitEffect](#portraiteffect) > | 支持的人像虚化效果列表。 |
**示例:**
```js
let portraitEffect = PortraitSession.getSupportedPortraitEffects();
```
### setPortraitEffect
setPortraitEffect(effect: PortraitEffect): void
设置人像虚化效果。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
| effect | [PortraitEffect](#portraiteffect) | 是 | 人像虚化效果,通过[getSupportedPortraitEffects](#getsupportedportraiteffects)接口获取。 |
**示例:**
```js
let portraitEffects = PortraitSession.getSupportedPortraitEffects();
if (!portraitEffects.empty()) {
PortraitSession.setPortraitEffect(portraitEffects[0]);
}
```
### getPortraitEffect
getPortraitEffect(): PortraitEffect
获取当前设置的人像虚化效果。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------- | ---------------------------- |
| [PortraitEffect](#portraiteffect) | 当前设置的人像虚化效果。 |
**示例:**
```js
let portraitEffects = PortraitSession.getSupportedPortraitEffects();
if (!portraitEffects.empty()) {
PortraitSession.setPortraitEffect(portraitEffects[0]);
}
```
## CameraOutput ## CameraOutput
......
...@@ -1415,7 +1415,7 @@ netCon.unregister(function (error) { ...@@ -1415,7 +1415,7 @@ netCon.unregister(function (error) {
### on('netCapabilitiesChange')<sup>8+</sup> ### on('netCapabilitiesChange')<sup>8+</sup>
on(type: 'netCapabilitiesChange', callback: Callback<{ netHandle: NetHandle, netCap: NetCapabilities }>): void on(type: 'netCapabilitiesChange', callback: Callback<NetCapabilityInfo>): void
订阅网络能力变化事件。 订阅网络能力变化事件。
...@@ -1428,7 +1428,7 @@ on(type: 'netCapabilitiesChange', callback: Callback<{ netHandle: NetHandle, net ...@@ -1428,7 +1428,7 @@ on(type: 'netCapabilitiesChange', callback: Callback<{ netHandle: NetHandle, net
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 订阅事件,固定为'netCapabilitiesChange'。<br/>netCapabilitiesChange:网络能力变化事件。 | | type | string | 是 | 订阅事件,固定为'netCapabilitiesChange'。<br/>netCapabilitiesChange:网络能力变化事件。 |
| callback | Callback<{ netHandle: [NetHandle](#nethandle), netCap: [NetCapabilities](#netcapabilities) }> | 是 | 回调函数,返回数据网络句柄(netHandle)和网络的能力信息(netCap)。| | callback | Callback<[NetCapabilityInfo](#netcapabilityinfo)> | 是 | 回调函数,返回数据网络句柄(netHandle)和网络的能力信息(netCap)。|
**示例:** **示例:**
...@@ -1950,6 +1950,17 @@ connection.getDefaultNet().then(function (netHandle) { ...@@ -1950,6 +1950,17 @@ connection.getDefaultNet().then(function (netHandle) {
| netCapabilities | [NetCapabilities](#netcapabilities) | 是 | 存储数据网络的传输能力和承载类型。 | | netCapabilities | [NetCapabilities](#netcapabilities) | 是 | 存储数据网络的传输能力和承载类型。 |
| bearerPrivateIdentifier | string | 否 | 网络标识符,Wi-Fi网络的标识符是"wifi",蜂窝网络的标识符是"slot0"(对应SIM卡1)。 | | bearerPrivateIdentifier | string | 否 | 网络标识符,Wi-Fi网络的标识符是"wifi",蜂窝网络的标识符是"slot0"(对应SIM卡1)。 |
## NetCapabilityInfo<sup>10+</sup>
提供承载数据网络能力的实例。
**系统能力**:SystemCapability.Communication.NetManager.Core
| 名称 | 类型 | 必填 | 说明 |
| ----------------------- | ----------------------------------- | ---- | ------------------------------------------------------------ |
| netHandle | [NetHandle](#nethandle) | 是 | 数据网络句柄。 |
| netCap | [NetCapabilities](#netcapabilities) | 否 | 存储数据网络的传输能力和承载类型。 |
## NetCapabilities<sup>8+</sup> ## NetCapabilities<sup>8+</sup>
网络的能力集。 网络的能力集。
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册