1e41f4b71Sopenharmony_ci# @ohos.app.ability.PhotoEditorExtensionAbility(图片编辑能力) 2e41f4b71Sopenharmony_ciPhotoEditorExtensionAbility继承自ExtensionAbility,开发者可通过PhotoEditorExtensionAbility实现图片编辑扩展页面。应用通过startAbilityByType拉起图片编辑类应用扩展面板后,由用户在面板上选择实现了PhotoEditorExtensionAbility的图片编辑扩展页面并拉起该页面。 3e41f4b71Sopenharmony_ci> **说明:** 4e41f4b71Sopenharmony_ci> 5e41f4b71Sopenharmony_ci> 本模块首批接口从API version 12 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块接口仅可在Stage模型下使用。 8e41f4b71Sopenharmony_ci## 导入模块 9e41f4b71Sopenharmony_ci```ts 10e41f4b71Sopenharmony_ciimport { PhotoEditorExtensionAbility } from '@kit.AbilityKit'; 11e41f4b71Sopenharmony_ci``` 12e41f4b71Sopenharmony_ci## 属性 13e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Ability.AppExtension.PhotoEditorExtension 14e41f4b71Sopenharmony_ci| 名称 |类型 |只读 |可选 |说明 | 15e41f4b71Sopenharmony_ci| ------------ | ------------ | ------------ | ------------ | ------------ | 16e41f4b71Sopenharmony_ci| context | [PhotoEditorExtensionContext](./js-apis-app-ability-photoEditorExtensionContext.md) | 否 | 是 | 上下文 | 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci## PhotoEditorExtensionAbility.onCreate 19e41f4b71Sopenharmony_cionCreate(): void 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciPhotoEditorExtensionAbility创建时回调,执行初始化业务逻辑操作。 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**模型约束:** 此接口仅可在Stage模型下使用。 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Ability.AppExtension.PhotoEditorExtension 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**示例:** 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci```ts 30e41f4b71Sopenharmony_ciimport { PhotoEditorExtensionAbility } from '@kit.AbilityKit'; 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ciconst TAG: string = '[testTag] ExamplePhotoEditorAbility'; 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ciexport default class ExamplePhotoEditorAbility extends PhotoEditorExtensionAbility { 35e41f4b71Sopenharmony_ci onCreate() { 36e41f4b71Sopenharmony_ci console.info(TAG, `onCreate`); 37e41f4b71Sopenharmony_ci } 38e41f4b71Sopenharmony_ci} 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci``` 41e41f4b71Sopenharmony_ci## PhotoEditorExtensionAbility.onStartContentEditing 42e41f4b71Sopenharmony_cionStartContentEditing(uri: string, want: Want, session: UIExtensionContentSession): void 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci当PhotoEditorExtensionAbility界面内容对象创建后调用,可以执行读取原始图片、加载页面等操作。 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci**模型约束:** 此接口仅可在Stage模型下使用。 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Ability.AppExtension.PhotoEditorExtension 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci**参数:** 51e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 52e41f4b71Sopenharmony_ci| ------------ | ------------ | ------------ | ------------ | 53e41f4b71Sopenharmony_ci| uri | string | 是 | 待编辑的原始图片[uri](../apis-core-file-kit/js-apis-file-fileuri.md),格式为file://\<bundleName>/\<sandboxPath>。 | 54e41f4b71Sopenharmony_ci| want | [Want](./js-apis-app-ability-want.md) | 是 | 当前PhotoEditorExtensionAbility的Want类型信息,包括ability名称、bundle名称等。 | 55e41f4b71Sopenharmony_ci| session | [UIExtensionContentSession](./js-apis-app-ability-uiExtensionContentSession.md) | 是 | PhotoEditorExtensionAbility界面内容相关信息。 | 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**示例:** 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci```ts 61e41f4b71Sopenharmony_ciimport { PhotoEditorExtensionAbility, Want, UIExtensionContentSession } from '@kit.AbilityKit'; 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ciconst TAG: string = '[testTag] ExamplePhotoEditorAbility'; 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ciexport default class ExamplePhotoEditorAbility extends PhotoEditorExtensionAbility { 66e41f4b71Sopenharmony_ci onStartContentEditing(uri: string, want: Want, session: UIExtensionContentSession) { 67e41f4b71Sopenharmony_ci console.info(TAG, `onStartContentEditing want: ${JSON.stringify(want)}, uri: ${uri}`); 68e41f4b71Sopenharmony_ci } 69e41f4b71Sopenharmony_ci} 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci``` 72e41f4b71Sopenharmony_ci## PhotoEditorExtensionAbility.onForeground 73e41f4b71Sopenharmony_cionForeground(): void 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ciPhotoEditorExtensionAbility生命周期回调,当PhotoEditorExtensionAbility从后台转到前台时触发。 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci**模型约束:** 此接口仅可在Stage模型下使用。 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Ability.AbilityRuntime.AbilityCore 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci**示例:** 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci```ts 84e41f4b71Sopenharmony_ciimport { PhotoEditorExtensionAbility } from '@kit.AbilityKit'; 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ciconst TAG: string = '[testTag] ExamplePhotoEditorAbility'; 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ciexport default class ExamplePhotoEditorAbility extends PhotoEditorExtensionAbility { 89e41f4b71Sopenharmony_ci onForeground() { 90e41f4b71Sopenharmony_ci console.info(TAG, `onForeground`); 91e41f4b71Sopenharmony_ci } 92e41f4b71Sopenharmony_ci} 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci``` 95e41f4b71Sopenharmony_ci## PhotoEditorExtensionAbility.onBackground 96e41f4b71Sopenharmony_cionBackground(): void 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ciPhotoEditorExtensionAbility生命周期回调,当PhotoEditorExtensionAbility从前台转到后台时触发。 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**模型约束:** 此接口仅可在Stage模型下使用。 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Ability.AbilityRuntime.AbilityCore 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci**示例:** 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci```ts 107e41f4b71Sopenharmony_ciimport { PhotoEditorExtensionAbility } from '@kit.AbilityKit'; 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ciconst TAG: string = '[testTag] ExamplePhotoEditorAbility'; 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ciexport default class ExamplePhotoEditorAbility extends PhotoEditorExtensionAbility { 112e41f4b71Sopenharmony_ci onBackground() { 113e41f4b71Sopenharmony_ci console.info(TAG, `onBackground`); 114e41f4b71Sopenharmony_ci } 115e41f4b71Sopenharmony_ci} 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci``` 118e41f4b71Sopenharmony_ci## PhotoEditorExtensionAbility.onDestroy 119e41f4b71Sopenharmony_cionDestroy(): void | Promise\<void> 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ciPhotoEditorExtensionAbility生命周期回调,在销毁时回调,执行资源清理等操作。 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci**模型约束:** 此接口仅可在Stage模型下使用。 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Ability.AppExtension.PhotoEditorExtension 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**返回值:** 128e41f4b71Sopenharmony_ci| 类型 |说明 | 129e41f4b71Sopenharmony_ci| ------------ | ------------ | 130e41f4b71Sopenharmony_ci| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci**示例:** 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci```ts 135e41f4b71Sopenharmony_ciimport { PhotoEditorExtensionAbility } from '@kit.AbilityKit'; 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ciconst TAG: string = '[testTag] ExamplePhotoEditorAbility'; 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ciexport default class ExamplePhotoEditorAbility extends PhotoEditorExtensionAbility { 140e41f4b71Sopenharmony_ci onDestroy() { 141e41f4b71Sopenharmony_ci console.info(TAG, `onDestroy`); 142e41f4b71Sopenharmony_ci } 143e41f4b71Sopenharmony_ci} 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci```