# Interface (ImageSource) > **NOTE** > > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. The **ImageSource** class provides APIs to obtain image information. Before calling any API in ImageSource, you must use [createImageSource](arkts-apis-image-f.md#imagecreateimagesource) to create an ImageSource instance. ## Modules to Import ```ts import { image } from '@kit.ImageKit'; ``` ## Properties **System capability**: SystemCapability.Multimedia.Image.ImageSource | Name | Type | Read Only| Optional| Description | | ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | | supportedFormats | Array\ | Yes | No | Supported formats, including .png, .jpeg, .bmp, .gif, .webp, .dng., and .heic12+ (depending on the hardware).| ## getImageInfo getImageInfo(index: number, callback: AsyncCallback\): void Obtains information about an image with the specified index. This API uses an asynchronous callback to return the result. **Widget capability**: This API can be used in ArkTS widgets since API version 12. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------- | ---- | ---------------------------------------- | | index | number | Yes | Index of the image source. The default value is **0**, indicating the first image. If this parameter is set to N, the (N+1)th image is used. For single-frame images, the value is always **0**. For multi-frame images such as animations, the value ranges from 0 to (Number of frames – 1). | | callback | AsyncCallback<[ImageInfo](arkts-apis-image-i.md#imageinfo)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the image information obtained; otherwise, **err** is an error object.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.getImageInfo(0, (error: BusinessError, imageInfo: image.ImageInfo) => { if (error) { console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`); } else { console.info('Succeeded in obtaining the image information.'); } }) ``` ## getImageInfo getImageInfo(callback: AsyncCallback\): void Obtains information about this image. This API uses an asynchronous callback to return the result. **Widget capability**: This API can be used in ArkTS widgets since API version 12. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------- | ---- | ---------------------------------------- | | callback | AsyncCallback<[ImageInfo](arkts-apis-image-i.md#imageinfo)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the image information obtained; otherwise, **err** is an error object.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.getImageInfo((err: BusinessError, imageInfo: image.ImageInfo) => { if (err) { console.error(`Failed to obtain the image information.code is ${err.code}, message is ${err.message}`); } else { console.info('Succeeded in obtaining the image information.'); } }) ``` ## getImageInfo getImageInfo(index?: number): Promise\ Obtains information about an image with the specified index. This API uses a promise to return the result. **Widget capability**: This API can be used in ArkTS widgets since API version 12. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name| Type | Mandatory| Description | | ----- | ------ | ---- | ------------------------------------- | | index | number | No | Index of the image source. The default value is **0**, indicating the first image. If this parameter is set to N, the (N+1)th image is used. For single-frame images, the value is always **0**. For multi-frame images such as animations, the value ranges from 0 to (Number of frames – 1).| **Return value** | Type | Description | | -------------------------------- | ---------------------- | | Promise<[ImageInfo](arkts-apis-image-i.md#imageinfo)> | Promise used to return the image information.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.getImageInfo(0) .then((imageInfo: image.ImageInfo) => { console.info('Succeeded in obtaining the image information.'); }).catch((error: BusinessError) => { console.error(`Failed to obtain the image information.code is ${error.code}, message is ${error.message}`); }) ``` ## getImageInfoSync12+ getImageInfoSync(index?: number): ImageInfo Obtains information about an image with the specified index. This API returns the result synchronously. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name| Type | Mandatory| Description | | ----- | ------ | ---- | ------------------------------------- | | index | number | No | Index of the image source. The default value is **0**, indicating the first image. If this parameter is set to N, the (N+1)th image is used. For single-frame images, the value is always **0**. For multi-frame images such as animations, the value ranges from 0 to (Number of frames – 1).| **Return value** | Type | Description | | -------------------------------- | ---------------------- | | [ImageInfo](arkts-apis-image-i.md#imageinfo) | Image information.| **Example** ```ts import { common } from '@kit.AbilityKit'; import { image } from '@kit.ImageKit'; // Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext. let context = this.getUIContext().getHostContext() as common.UIAbilityContext; // 'test.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. let filePath: string = context.filesDir + "/test.jpg"; let imageSource = image.createImageSource(filePath); let imageInfo = imageSource.getImageInfoSync(0); if (imageInfo == undefined) { console.error('Failed to obtain the image information.'); } else { console.info('Succeeded in obtaining the image information.'); console.info('imageInfo.size.height:' + imageInfo.size.height); console.info('imageInfo.size.width:' + imageInfo.size.width); } ``` ## getImageProperty11+ getImageProperty(key:PropertyKey, options?: ImagePropertyOptions): Promise\ Obtains the value of a property with the specified index in this image. This API uses a promise to return the result. This API applies only to images that are in JPEG, PNG, or HEIF12+ (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ------- | ---------------------------------------------------- | ---- | ------------------------------------ | | key | [PropertyKey](arkts-apis-image-e.md#propertykey7) | Yes | Name of the property. | | options | [ImagePropertyOptions](arkts-apis-image-i.md#imagepropertyoptions11) | No | Image properties, including the image index and default property value.| **Return value** | Type | Description | | ---------------- | ----------------------------------------------------------------- | | Promise\ | Promise used to return the property value. If the operation fails, the default value is returned.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | | 62980096 | The operation failed. Possible cause: 1.Image upload exception. 2. Decoding process exception. 3. Insufficient memory. | | 62980103 | The image data is not supported. | | 62980110 | The image source data is incorrect. | | 62980111 | The image source data is incomplete. | | 62980112 | The image format does not match. | | 62980113| Unknown image format.The image data provided is not in a recognized or supported format, or it may be occorrupted. | | 62980115 | Invalid image parameter. | | 62980118 | Failed to create the image plugin. | | 62980122 | Failed to decode the image header. | | 62980123| The image does not support EXIF decoding. | | 62980135| The EXIF value is invalid. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let options: image.ImagePropertyOptions = { index: 0, defaultValue: '9999' } imageSourceApi.getImageProperty(image.PropertyKey.BITS_PER_SAMPLE, options) .then((data: string) => { console.info('Succeeded in getting the value of the specified attribute key of the image.'); }).catch((error: BusinessError) => { console.error('Failed to get the value of the specified attribute key of the image.'); }) ``` ## getImageProperties12+ getImageProperties(key: Array<PropertyKey>): Promise> Obtains the values of properties with the given names in this image. This API uses a promise to return the result. This API applies only to images that are in JPEG, PNG, or HEIF (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ------- | ---------------------------------------------------- | ---- | ------------------------------------ | | key | Array\<[PropertyKey](arkts-apis-image-e.md#propertykey7)> | Yes | Array of properties names. | **Return value** | Type | Description | | ---------------- | ----------------------------------------------------------------- | | Promise\> | Promise used to return the property values. If the operation fails, **null** is returned.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | | 62980096| The operation failed. Possible cause: 1.Image upload exception. 2. Decoding process exception. 3. Insufficient memory. | | 62980110| The image source data is incorrect. | | 62980113| Unknown image format.The image data provided is not in a recognized or supported format, or it may be occorrupted. | | 62980116| Failed to decode the image. | **Example** ```ts import { image } from '@kit.ImageKit'; import { BusinessError } from '@kit.BasicServicesKit'; let key = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH]; imageSourceApi.getImageProperties(key).then((data) => { console.info(JSON.stringify(data)); }).catch((err: BusinessError) => { console.error(JSON.stringify(err)); }); ``` ## getImagePropertySync20+ getImagePropertySync(key:PropertyKey): string Obtains the value of a specified EXIF property. This API returns the property value in a string. >**NOTE** > > This API applies only to images that are in JPEG, PNG, or HEIF (depending on the hardware) format and contain the EXIF information. > > EXIF information is metadata of the image, including shooting time, camera model, aperture, focal length, and ISO. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ------- | ---------------------------------------------------- | ---- | ------------------------------------ | | key | [PropertyKey](arkts-apis-image-e.md#propertykey7) | Yes | Name of the property. | **Return value** | Type | Description | | ---------------- | ----------------------------------------------------------------- | | string | Value of the specified EXIF property. If retrieval fails, the default value of the property is returned. For details about the meaning of each data value, see [PropertyKey](arkts-apis-image-e.md#propertykey7).| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 7700101 | Bad source. e.g.,1. Image has invalid width or height. 2. Image source incomplete. 3. Read image data failed. 4. Codec create failed.| | 7700102 | Unsupported MIME type.| | 7700202 | Unsupported metadata. For example, key is not supported.| **Example** ```ts import { image } from '@kit.ImageKit'; import { common } from '@kit.AbilityKit'; // Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext. let context = this.getUIContext().getHostContext() as common.UIAbilityContext; let resourceMgr = context.resourceManager; if (resourceMgr == null) { return; } let fd = resourceMgr.getRawFdSync("example.jpg"); const imageSourceApi = image.createImageSource(fd); console.info("getImagePropertySync"); let bits_per_sample = imageSourceApi.getImagePropertySync(image.PropertyKey.BITS_PER_SAMPLE); console.info("bits_per_sample : " + bits_per_sample); ``` ## modifyImageProperty11+ modifyImageProperty(key: PropertyKey, value: string): Promise\ Modifies the value of a property in this image. This API uses a promise to return the result. This API applies only to images that are in JPEG, PNG, or HEIF12+ (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. > **NOTE** > > The property byte length is changed when the **modifyImageProperty** API is called to modify the value of a property. Currently, you can call the API in an ImageSource instance created based on a file descriptor or path, but not an ImageSource instance created based on buffers. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ------- | ------ | ---- | ------------ | | key | [PropertyKey](arkts-apis-image-e.md#propertykey7) | Yes | Name of the property.| | value | string | Yes | New value of the property. | **Return value** | Type | Description | | -------------- | --------------------------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; | | 62980123| The image does not support EXIF decoding. | | 62980133| The EXIF data is out of range. | | 62980135| The EXIF value is invalid. | | 62980146| The EXIF data failed to be written to the file. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.modifyImageProperty(image.PropertyKey.IMAGE_WIDTH, "120").then(() => { imageSourceApi.getImageProperty(image.PropertyKey.IMAGE_WIDTH).then((width: string) => { console.info(`ImageWidth is :${width}`); }).catch((error: BusinessError) => { console.error('Failed to get the Image Width.'); }) }).catch((error: BusinessError) => { console.error('Failed to modify the Image Width'); }) ``` ## modifyImageProperties12+ modifyImageProperties(records: Record): Promise\ Modifies the values of properties in this image. This API uses a promise to return the result. This API applies only to images that are in JPEG, PNG, or HEIF (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. > **NOTE** > > The property byte length is changed when the **modifyImageProperties** API is called to modify the values of properties. Currently, you can call the API in an ImageSource instance created based on a file descriptor or path, but not an ImageSource instance created based on buffers. > **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ------- | ------ | ---- | ------------ | | records | Record<[PropertyKey](arkts-apis-image-e.md#propertykey7), string \| null> | Yes | Array of property names and property values.| **Return value** | Type | Description | | -------------- | --------------------------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed; | | 62980123| The image does not support EXIF decoding. | | 62980135| The EXIF value is invalid. | | 62980146| The EXIF data failed to be written to the file. | **Example** ```ts import { image } from '@kit.ImageKit'; import { BusinessError } from '@kit.BasicServicesKit'; let keyValues: Record = { [image.PropertyKey.IMAGE_WIDTH] : "1024", [image.PropertyKey.IMAGE_LENGTH] : "1024" }; let checkKey = [image.PropertyKey.IMAGE_WIDTH, image.PropertyKey.IMAGE_LENGTH]; imageSourceApi.modifyImageProperties(keyValues).then(() => { imageSourceApi.getImageProperties(checkKey).then((data) => { console.info(JSON.stringify(data)); }).catch((err: BusinessError) => { console.error(JSON.stringify(err)); }); }).catch((err: BusinessError) => { console.error(JSON.stringify(err)); }); ``` ## updateData9+ updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number): Promise\ Updates incremental data. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ---------- | ----------- | ---- | ------------ | | buf | ArrayBuffer | Yes | Buffer for storing the incremental data. | | isFinished | boolean | Yes | Whether data update is complete. The value **true** means that the data update is complete and the last segment of data is stored in the buffer. The value **false** means that the data update is still in progress.| | offset | number | Yes | Offset of the data in the buffer, measured from the start of the entire image file, in bytes. | | length | number | Yes | Length of the buffer, in bytes. | **Return value** | Type | Description | | -------------- | -------------------------- | | Promise\ | Promise that returns no value.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; const array: ArrayBuffer = new ArrayBuffer(100); imageSourceApi.updateData(array, false, 0, 10).then(() => { console.info('Succeeded in updating data.'); }).catch((err: BusinessError) => { console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); }) ``` ## updateData9+ updateData(buf: ArrayBuffer, isFinished: boolean, offset: number, length: number, callback: AsyncCallback\): void Updates incremental data. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ---------- | ------------------- | ---- | -------------------- | | buf | ArrayBuffer | Yes | Buffer for storing the incremental data. | | isFinished | boolean | Yes | Whether data update is complete. The value **true** means that the data update is complete and the last segment of data is stored in the buffer. The value **false** means that the data update is still in progress.| | offset | number | Yes | Offset of the data in the buffer, measured from the start of the entire image file, in bytes. | | length | number | Yes | Length of the buffer, in bytes. | | callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; const array: ArrayBuffer = new ArrayBuffer(100); imageSourceApi.updateData(array, false, 0, 10, (err: BusinessError) => { if (err) { console.error(`Failed to update data.code is ${err.code},message is ${err.message}`); } else { console.info('Succeeded in updating data.'); } }) ``` ## createPicture13+ createPicture(options?: DecodingOptionsForPicture): Promise\ Creates a Picture object based on decoding options. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ------- | ------------------------------------------------------ | ---- | ---------- | | options | [DecodingOptionsForPicture](arkts-apis-image-i.md#decodingoptionsforpicture13) | No | Decoding options.| **Return value** | Type | Description | | ---------------------------- | -------------------------- | | Promise\<[Picture](arkts-apis-image-Picture.md)> | Promise used to return the Picture object.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error.Possible causes: 1.Mandatory parameters are left unspecified.2.Incorrect parameter types; 3.Parameter verification failed. | | 7700301 | Failed to decode image. | **Example** ```ts import { image } from '@kit.ImageKit'; async function CreatePicture() { let options: image.DecodingOptionsForPicture = { desiredAuxiliaryPictures: [image.AuxiliaryPictureType.GAINMAP] // GAINMAP indicates the type of the auxiliary picture to be decoded. }; let pictureObj: image.Picture = await imageSourceApi.createPicture(options); if (pictureObj != null) { console.info('Create picture succeeded'); } else { console.error('Create picture failed'); } } ``` ## createPictureAtIndex20+ createPictureAtIndex(index: number): Promise\ Creates a Picture object from the specified index of an image. Only GIF images are supported. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------ | | index | number | Yes | Index of the image. The value range is [0, Number of frames – 1].| **Return value** | Type | Description | | ---------------------------- | ---------------------------- | | Promise\<[Picture](arkts-apis-image-Picture.md)> | Promise used to return the Picture object.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 7700101 | Bad source. | | 7700102 | Unsupported MIME type. | | 7700103 | Image too large. | | 7700203 | Unsupported options. For example, index is invalid. | | 7700301 | Decoding failed. | **Example** ```ts import { image } from '@kit.ImageKit'; async function CreatePictures() { let frameCount: number = await imageSourceApi.getFrameCount(); for (let index = 0; index < frameCount; index++) { try { let pictureObj: image.Picture = await imageSourceApi.createPictureAtIndex(index); console.info('Create picture succeeded for frame: ' + index); } catch (e) { console.error('Create picture failed for frame: ' + index); } } } ``` ## createPixelMap7+ createPixelMap(options?: DecodingOptions): Promise\ Creates a PixelMap object based on decoding options. This API uses a promise to return the result. Starting from API version 15, you are advised to use [createPixelMapUsingAllocator](#createpixelmapusingallocator15). This API can be used to specify the memory type [AllocatorType](arkts-apis-image-e.md#allocatortype15) of the output PixelMap. For details, see [Allocating Memory for Image Decoding (ArkTS)](../../media/image/image-allocator-type.md). **Widget capability**: This API can be used in ArkTS widgets since API version 12. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ------- | ------------------------------------ | ---- | ---------- | | options | [DecodingOptions](arkts-apis-image-i.md#decodingoptions7) | No | Decoding options.| **Return value** | Type | Description | | -------------------------------- | --------------------- | | Promise\<[PixelMap](arkts-apis-image-PixelMap.md)> | Promise used to return the PixelMap object.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.createPixelMap().then((pixelMap: image.PixelMap) => { console.info('Succeeded in creating pixelMap object through image decoding parameters.'); }).catch((error: BusinessError) => { console.error('Failed to create pixelMap object through image decoding parameters.'); }) ``` ## createPixelMap7+ createPixelMap(callback: AsyncCallback\): void Creates a PixelMap object based on the default parameters. This API uses an asynchronous callback to return the result. Starting from API version 15, you are advised to use [createPixelMapUsingAllocator](#createpixelmapusingallocator15). This API can be used to specify the memory type [AllocatorType](arkts-apis-image-e.md#allocatortype15) of the output PixelMap. For details, see [Allocating Memory for Image Decoding (ArkTS)](../../media/image/image-allocator-type.md). **Widget capability**: This API can be used in ArkTS widgets since API version 12. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------- | ---- | -------------------------- | | callback | AsyncCallback<[PixelMap](arkts-apis-image-PixelMap.md)> | Yes | Callback used to return the result. If the operation is successful, **err** is undefined and **data** is the PixelMap object obtained; otherwise, **err** is an error object.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.createPixelMap((err: BusinessError, pixelMap: image.PixelMap) => { if (err) { console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); } else { console.info('Succeeded in creating pixelMap object.'); } }) ``` ## createPixelMap7+ createPixelMap(options: DecodingOptions, callback: AsyncCallback\): void Creates a PixelMap object based on decoding options. This API uses a promise to return the result. Starting from API version 15, you are advised to use [createPixelMapUsingAllocator](#createpixelmapusingallocator15). This API can be used to specify the memory type [AllocatorType](arkts-apis-image-e.md#allocatortype15) of the output PixelMap. For details, see [Allocating Memory for Image Decoding (ArkTS)](../../media/image/image-allocator-type.md). **Widget capability**: This API can be used in ArkTS widgets since API version 12. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------- | ---- | -------------------------- | | options | [DecodingOptions](arkts-apis-image-i.md#decodingoptions7) | Yes | Decoding options. | | callback | AsyncCallback<[PixelMap](arkts-apis-image-PixelMap.md)> | Yes | Callback used to return the result. If the operation is successful, **err** is undefined and **data** is the PixelMap object obtained; otherwise, **err** is an error object.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let decodingOptions: image.DecodingOptions = { sampleSize: 1, editable: true, desiredSize: { width: 1, height: 2 }, rotate: 10, desiredPixelFormat: image.PixelMapFormat.RGBA_8888, desiredRegion: { size: { width: 1, height: 2 }, x: 0, y: 0 }, // If both desiredSize and desiredRegion are passed to the decoding API, you must also include cropAndScaleStrategy to determine whether to crop or scale first. CROP_FIRST is recommended. cropAndScaleStrategy: image.CropAndScaleStrategy.CROP_FIRST, index: 0 }; imageSourceApi.createPixelMap(decodingOptions, (err: BusinessError, pixelMap: image.PixelMap) => { if (err) { console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); } else { console.info('Succeeded in creating pixelMap object.'); } }) ``` ## createPixelMapSync12+ createPixelMapSync(options?: DecodingOptions): PixelMap Creates a PixelMap object based on decoding options. This API returns the result synchronously. Starting from API version 15, you are advised to use [createPixelMapUsingAllocatorSync](#createpixelmapusingallocatorsync15). This API can be used to specify the memory type [AllocatorType](arkts-apis-image-e.md#allocatortype15) of the output PixelMap. For details, see [Allocating Memory for Image Decoding (ArkTS)](../../media/image/image-allocator-type.md). **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------- | ---- | -------------------------- | | options | [DecodingOptions](arkts-apis-image-i.md#decodingoptions7) | No | Decoding options. | **Return value** | Type | Description | | -------------------------------- | --------------------- | | [PixelMap](arkts-apis-image-PixelMap.md) | PixelMap object.| **Example** ```ts import { common } from '@kit.AbilityKit'; import { image } from '@kit.ImageKit'; // Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext. let context = this.getUIContext().getHostContext() as common.UIAbilityContext; // 'test.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. let filePath: string = context.filesDir + "/test.jpg"; let imageSource = image.createImageSource(filePath); let decodingOptions: image.DecodingOptions = { sampleSize: 1, editable: true, desiredSize: { width: 1, height: 2 }, rotate: 10, desiredPixelFormat: image.PixelMapFormat.RGBA_8888, desiredRegion: { size: { width: 1, height: 2 }, x: 0, y: 0 }, // If both desiredSize and desiredRegion are passed to the decoding API, you must also include cropAndScaleStrategy to determine whether to crop or scale first. CROP_FIRST is recommended. cropAndScaleStrategy: image.CropAndScaleStrategy.CROP_FIRST, index: 0 }; let pixelmap = imageSource.createPixelMapSync(decodingOptions); if (pixelmap != undefined) { console.info('Succeeded in creating pixelMap object.'); } else { console.error('Failed to create pixelMap.'); } ``` ## createPixelMapList10+ createPixelMapList(options?: DecodingOptions): Promise> Creates an array of PixelMap objects based on decoding options. This API uses a promise to return the result. For dynamic images such as GIF and WebP images, this API returns the data of each frame of the image. For static images, this API returns the data of the unique frame of the image. > **NOTE** > > This function decodes all frames at once. If the number of frames is high or the size of individual frames is large, it can lead to significant memory usage. In these cases, you are advised to use the **Image** component for displaying animations. The **Image** component decodes frames one by one, which uses less memory than this function. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------- | ---- | -------------------------- | | options | [DecodingOptions](arkts-apis-image-i.md#decodingoptions7) | No | Decoding options. | **Return value** | Type | Description | | -------------------------------- | --------------------- | | Promise> | Promise used to return an array of PixelMap objects.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 62980096| The operation failed. Possible cause: 1.Image upload exception. 2. Decoding process exception. 3. Insufficient memory. | | 62980099 | The shared memory data is abnormal. | | 62980101 | The image data is abnormal. | | 62980103| The image data is not supported. | | 62980106 | The image data is too large. This status code is thrown when an error occurs during the process of checking size. | | 62980109 | Failed to crop the image. | | 62980111| The image source data is incomplete. | | 62980115 | Invalid image parameter. | | 62980116 | Failed to decode the image. | | 62980118| Failed to create the image plugin. | | 62980137 | Invalid media operation. | | 62980173 | The DMA memory does not exist. | | 62980174 | The DMA memory data is abnormal. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let decodeOpts: image.DecodingOptions = { sampleSize: 1, editable: true, desiredSize: { width: 198, height: 202 }, rotate: 0, desiredPixelFormat: image.PixelMapFormat.RGBA_8888, index: 0, }; imageSourceApi.createPixelMapList(decodeOpts).then((pixelMapList: Array) => { console.info('Succeeded in creating pixelMapList object.'); }).catch((err: BusinessError) => { console.error(`Failed to create pixelMapList object, error code is ${err}`); }) ``` ## createPixelMapList10+ createPixelMapList(callback: AsyncCallback>): void Creates an array of PixelMap objects based on the default parameters. This API uses an asynchronous callback to return the result. For dynamic images such as GIF and WebP images, this API returns the data of each frame of the image. For static images, this API returns the data of the unique frame of the image. > **NOTE** > > This function decodes all frames at once. If the number of frames is high or the size of individual frames is large, it can lead to significant memory usage. In these cases, you are advised to use the **Image** component for displaying animations. The **Image** component decodes frames one by one, which uses less memory than this function. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------- | ---- | -------------------------- | | callback | AsyncCallback> | Yes | Callback used to return the result. If the operation is successful, **err** is undefined and **data** is the array of PixelMap objects obtained; otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 62980096 | The operation failed. Possible cause: 1.Image upload exception. 2. Decoding process exception. 3. Insufficient memory. | | 62980099 | The shared memory data is abnormal. | | 62980101 | The image data is abnormal. | | 62980103 | The image data is not supported. | | 62980106 | The image data is too large. This status code is thrown when an error occurs during the process of checking size. | | 62980109 | Failed to crop the image. | | 62980111 | The image source data is incomplete. | | 62980115 | Invalid image parameter. | | 62980116 | Failed to decode the image. | | 62980118 | Failed to create the image plugin. | | 62980137 | Invalid media operation. | | 62980173 | The DMA memory does not exist. | | 62980174 | The DMA memory data is abnormal. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.createPixelMapList((err: BusinessError, pixelMapList: Array) => { if (err) { console.error(`Failed to create pixelMapList object, error code is ${err}`); } else { console.info('Succeeded in creating pixelMapList object.'); } }) ``` ## createPixelMapList10+ createPixelMapList(options: DecodingOptions, callback: AsyncCallback>): void Creates an array of PixelMap objects based on decoding options. This API uses an asynchronous callback to return the result. For dynamic images such as GIF and WebP images, this API returns the data of each frame of the image. For static images, this API returns the data of the unique frame of the image. > **NOTE** > > This function decodes all frames at once. If the number of frames is high or the size of individual frames is large, it can lead to significant memory usage. In these cases, you are advised to use the **Image** component for displaying animations. The **Image** component decodes frames one by one, which uses less memory than this function. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------- | ---- | ---------------------------------- | | options | [DecodingOptions](arkts-apis-image-i.md#decodingoptions7) | Yes| Decoding options.| | callback | AsyncCallback> | Yes | Callback used to return the result. If the operation is successful, **err** is undefined and **data** is the array of PixelMap objects obtained; otherwise, **err** is an error object. | **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 62980096 | The operation failed. Possible cause: 1.Image upload exception. 2. Decoding process exception. 3. Insufficient memory. | | 62980099 | The shared memory data is abnormal. | | 62980101 | The image data is abnormal. | | 62980103 | The image data is not supported. | | 62980106 | The image data is too large. This status code is thrown when an error occurs during the process of checking size. | | 62980109 | Failed to crop the image. | | 62980111 | The image source data is incomplete. | | 62980115 | Invalid image parameter. | | 62980116 | Failed to decode the image. | | 62980118 | Failed to create the image plugin. | | 62980137 | Invalid media operation. | | 62980173 | The DMA memory does not exist. | | 62980174 | The DMA memory data is abnormal. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let decodeOpts: image.DecodingOptions = { sampleSize: 1, editable: true, desiredSize: { width: 198, height: 202 }, rotate: 0, desiredPixelFormat: image.PixelMapFormat.RGBA_8888, index: 0, }; imageSourceApi.createPixelMapList(decodeOpts, (err: BusinessError, pixelMapList: Array) => { if (err) { console.error(`Failed to create pixelMapList object, error code is ${err}`); } else { console.info('Succeeded in creating pixelMapList object.'); } }) ``` ## createPixelMapUsingAllocator15+ createPixelMapUsingAllocator(options?: DecodingOptions, allocatorType?: AllocatorType): Promise\ Creates a PixelMap object based on decoding options and memory type. This API uses a promise to return the result. For details about how to use the API, see [Allocating Memory for Image Decoding (ArkTS)](../../media/image/image-allocator-type.md). **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ------------- | ------------------------------------ | ---- | ------------------------ | | options | [DecodingOptions](arkts-apis-image-i.md#decodingoptions7) | No | Decoding options. | | allocatorType | [AllocatorType](arkts-apis-image-e.md#allocatortype15) | No | Type of the memory. The default value is **AllocatorType.AUTO**.| **Return value** | Type | Description | | -------------------------------- | --------------------------- | | Promise\<[PixelMap](arkts-apis-image-PixelMap.md)> | Promise used to return the PixelMap object.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error.Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types;3.Parameter verification failed. | | 7700101 | Bad source. e.g.,1. Image has invalid width or height. 2. Image source incomplete. 3. Read image data failed. 4. Codec create failed. | | 7700102 | Unsupported mimetype. | | 7700103 | Image too large. This status code is thrown when an error occurs during the process of checking size. | | 7700201 | Unsupported allocator type, e.g., use share memory to decode a HDR image as only DMA supported hdr metadata. | | 7700203 | Unsupported options, e.g., cannot convert image into desired pixel format. | | 7700301 | Failed to decode image. | | 7700302 | Failed to allocate memory. | **Example** ```ts import { common } from '@kit.AbilityKit'; import image from '@ohos.multimedia.image'; // Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext. let context = this.getUIContext().getHostContext() as common.UIAbilityContext; // 'test.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. let filePath: string = context.filesDir + "/test.jpg"; let imageSource = image.createImageSource(filePath); let decodingOptions: image.DecodingOptions = { editable: true, desiredSize: { width: 3072, height: 4096 }, rotate: 10, desiredPixelFormat: image.PixelMapFormat.RGBA_8888, desiredRegion: { size: { width: 3072, height: 4096 }, x: 0, y: 0 }, // If both desiredSize and desiredRegion are passed to the decoding API, you must also include cropAndScaleStrategy to determine whether to crop or scale first. CROP_FIRST is recommended. cropAndScaleStrategy: image.CropAndScaleStrategy.CROP_FIRST, index: 0 }; let pixelmap = imageSource.createPixelMapUsingAllocator(decodingOptions, image.AllocatorType.AUTO); if (pixelmap != undefined) { console.info('Succeeded in creating pixelMap object.'); } else { console.error('Failed to create pixelMap.'); } ``` ## createPixelMapUsingAllocatorSync15+ createPixelMapUsingAllocatorSync(options?: DecodingOptions, allocatorType?: AllocatorType): PixelMap Creates a PixelMap object based on decoding options and memory type. This API returns the result synchronously. For details about how to use the API, see [Allocating Memory for Image Decoding (ArkTS)](../../media/image/image-allocator-type.md). **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ------------- | ------------------------------------ | ---- | ------------------------ | | options | [DecodingOptions](arkts-apis-image-i.md#decodingoptions7) | No | Decoding options. | | allocatorType | [AllocatorType](arkts-apis-image-e.md#allocatortype15) | No | Type of the memory. The default value is **AllocatorType.AUTO**.| **Return value** | Type | Description | | ---------------------- | ---------------------- | | [PixelMap](arkts-apis-image-PixelMap.md) | PixelMap object.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error.Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types;3.Parameter verification failed. | | 7700101 | Bad source. e.g.,1. Image has invalid width or height. 2. Image source incomplete. 3. Read image data failed. 4. Codec create failed. | | 7700102 | Unsupported mimetype. | | 7700103 | Image too large. This status code is thrown when an error occurs during the process of checking size. | | 7700201 | Unsupported allocator type, e.g., use share memory to decode a HDR image as only DMA supported hdr metadata. | | 7700203 | Unsupported options, e.g., cannot convert image into desired pixel format. | | 7700301 | Failed to decode image. | | 7700302 | Failed to allocate memory. | **Example** ```ts import { common } from '@kit.AbilityKit'; import image from '@ohos.multimedia.image'; // Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext. let context = this.getUIContext().getHostContext() as common.UIAbilityContext; // 'test.jpg' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed. let filePath: string = context.filesDir + "/test.jpg"; let imageSource = image.createImageSource(filePath); let decodingOptions: image.DecodingOptions = { editable: true, desiredSize: { width: 3072, height: 4096 }, rotate: 10, desiredPixelFormat: image.PixelMapFormat.RGBA_8888, desiredRegion: { size: { width: 3072, height: 4096 }, x: 0, y: 0 }, // If both desiredSize and desiredRegion are passed to the decoding API, you must also include cropAndScaleStrategy to determine whether to crop or scale first. CROP_FIRST is recommended. cropAndScaleStrategy: image.CropAndScaleStrategy.CROP_FIRST, index: 0 }; let pixelmap = imageSource.createPixelMapUsingAllocatorSync(decodingOptions, image.AllocatorType.AUTO); if (pixelmap != undefined) { console.info('Succeeded in creating pixelMap object.'); } else { console.error('Failed to create pixelMap.'); } ``` ## getDelayTimeList10+ getDelayTimeList(callback: AsyncCallback>): void Obtains an array of delay times. This API uses an asynchronous callback to return the result. This API applies only to images in GIF or WebP format. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------- | ---- | ---------------------------------- | | callback | AsyncCallback> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the array of delay times obtained; otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 62980096| The operation failed. Possible cause: 1.Image upload exception. 2. Decoding process exception. 3. Insufficient memory. | | 62980110| The image source data is incorrect. | | 62980111| The image source data is incomplete. | | 62980115 | Invalid image parameter. | | 62980116| Failed to decode the image. | | 62980118| Failed to create the image plugin. | | 62980122| Failed to decode the image header. | | 62980149 | Invalid MIME type for the image source. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.getDelayTimeList((err: BusinessError, delayTimes: Array) => { if (err) { console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); } else { console.info('Succeeded in getting delayTimes object.'); } }) ``` ## getDelayTimeList10+ getDelayTimeList(): Promise> Obtains an array of delay times. This API uses a promise to return the result. This API applies only to images in GIF or WebP format. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Return value** | Type | Description | | -------------- | --------------------------- | | Promise> | Promise used to return an array of delay times.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 62980096 | The operation failed. Possible cause: 1.Image upload exception. 2. Decoding process exception. 3. Insufficient memory. | | 62980110 | The image source data is incorrect. | | 62980111 | The image source data is incomplete. | | 62980115 | Invalid image parameter. | | 62980116 | Failed to decode the image. | | 62980118 | Failed to create the image plugin. | | 62980122 | Failed to decode the image header. | | 62980149 | Invalid MIME type for the image source. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.getDelayTimeList().then((delayTimes: Array) => { console.info('Succeeded in getting delayTimes object.'); }).catch((err: BusinessError) => { console.error(`Failed to get delayTimes object.code is ${err.code},message is ${err.message}`); }) ``` ## getFrameCount10+ getFrameCount(callback: AsyncCallback\): void Obtains the number of frames. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------- | ---- | ---------------------------------- | | callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the number of frames obtained; otherwise, **err** is an error object.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 62980096| The operation failed. Possible cause: 1.Image upload exception. 2. Decoding process exception. 3. Insufficient memory. | | 62980111| The image source data is incomplete. | | 62980112| The image format does not match. | | 62980113| Unknown image format.The image data provided is not in a recognized or supported format, or it may be occorrupted. | | 62980115| Invalid image parameter. | | 62980116| Failed to decode the image. | | 62980118| Failed to create the image plugin. | | 62980122| Failed to decode the image header. | | 62980137| Invalid media operation. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.getFrameCount((err: BusinessError, frameCount: number) => { if (err) { console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); } else { console.info('Succeeded in getting frame count.'); } }) ``` ## getFrameCount10+ getFrameCount(): Promise\ Obtains the number of frames. This API uses a promise to return the result. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Return value** | Type | Description | | -------------- | --------------------------- | | Promise\ | Promise used to return the number of frames.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 62980096 | The operation failed. Possible cause: 1.Image upload exception. 2. Decoding process exception. 3. Insufficient memory. | | 62980111 | The image source data is incomplete. | | 62980112 | The image format does not match. | | 62980113| Unknown image format.The image data provided is not in a recognized or supported format, or it may be occorrupted. | | 62980115 | Invalid image parameter. | | 62980116 | Failed to decode the image. | | 62980118 | Failed to create the image plugin. | | 62980122 | Failed to decode the image header. | | 62980137 | Invalid media operation. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.getFrameCount().then((frameCount: number) => { console.info('Succeeded in getting frame count.'); }).catch((err: BusinessError) => { console.error(`Failed to get frame count.code is ${err.code},message is ${err.message}`); }) ``` ## getDisposalTypeList12+ getDisposalTypeList(): Promise\> Obtains the list of disposal types. This API uses a promise to return the result. It is used only for GIF images. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Return value** | Type | Description | | -------------- | --------------------------- | | Promise\> | Promise used to return an array of disposal types.| **Error codes** For details about the error codes, see [Image Error Codes](errorcode-image.md). | ID| Error Message| | ------- | --------------------------------------------| | 62980096 | The operation failed. Possible cause: 1.Image upload exception. 2. Decoding process exception. 3. Insufficient memory. | | 62980101 | The image data is abnormal. | | 62980137 | Invalid media operation. | | 62980149 | Invalid MIME type for the image source. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.getDisposalTypeList().then((disposalTypes: Array) => { console.info('Succeeded in getting disposalTypes object.'); }).catch((err: BusinessError) => { console.error(`Failed to get disposalTypes object.code ${err.code},message is ${err.message}`); }) ``` ## release release(callback: AsyncCallback\): void Releases this ImageSource instance. This API uses an asynchronous callback to return the result. ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the ImageSource object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the object is no longer required. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------- | ---- | ---------------------------------- | | callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.release((err: BusinessError) => { if (err) { console.error(`Failed to release the image source instance.code ${err.code},message is ${err.message}`); } else { console.info('Succeeded in releasing the image source instance.'); } }) ``` ## release release(): Promise\ Releases this ImageSource instance. This API uses a promise to return the result. ArkTS supports memory reclamation. Even if the application does not call **release()**, the memory of the ImageSource object will be released by the system. However, images usually occupy a large amount of memory. Therefore, it is recommended that the application proactively call the API to release the memory when the object is no longer required. **System capability**: SystemCapability.Multimedia.Image.ImageSource **Return value** | Type | Description | | -------------- | --------------------------- | | Promise\ | Promise that returns no value.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.release().then(() => { console.info('Succeeded in releasing the image source instance.'); }).catch((error: BusinessError) => { console.error(`Failed to release the image source instance.code ${error.code},message is ${error.message}`); }) ``` ## getImageProperty(deprecated) getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\ Obtains the value of a property with the specified index in this image. This API uses a promise to return the result. This API applies only to images that are in JPEG, PNG, or HEIF12+ (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. > **NOTE** > > This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ------- | ---------------------------------------------------- | ---- | ------------------------------------ | | key | string | Yes | Name of the property. | | options | [GetImagePropertyOptions](arkts-apis-image-i.md#getimagepropertyoptionsdeprecated) | No | Image properties, including the image index and default property value.| **Return value** | Type | Description | | ---------------- | ----------------------------------------------------------------- | | Promise\ | Promise used to return the property value. If the operation fails, the default value is returned.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.getImageProperty("BitsPerSample") .then((data: string) => { console.info('Succeeded in getting the value of the specified attribute key of the image.'); }).catch((error: BusinessError) => { console.error('Failed to get the value of the specified attribute key of the image.'); }) ``` ## getImageProperty(deprecated) getImageProperty(key:string, callback: AsyncCallback\): void Obtains the value of a property with the specified index in this image. This API uses an asynchronous callback to return the result. This API applies only to images that are in JPEG, PNG, or HEIF12+ (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. > **NOTE** > > This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | ------------------------------------------------------------ | | key | string | Yes | Name of the property. | | callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the property value obtained; otherwise, **err** is an error object.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.getImageProperty("BitsPerSample", (error: BusinessError, data: string) => { if (error) { console.error('Failed to get the value of the specified attribute key of the image.'); } else { console.info('Succeeded in getting the value of the specified attribute key of the image.'); } }) ``` ## getImageProperty(deprecated) getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCallback\): void Obtains the value of a property in this image. This API uses an asynchronous callback to return the result. This API applies only to images that are in JPEG, PNG, or HEIF12+ (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. > **NOTE** > > This API is deprecated since API version 11. You are advised to use [getImageProperty](#getimageproperty11). **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------- | | key | string | Yes | Name of the property. | | options | [GetImagePropertyOptions](arkts-apis-image-i.md#getimagepropertyoptionsdeprecated) | Yes | Image properties, including the image index and default property value. | | callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the property value obtained; otherwise, **err** is an error object.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let property: image.GetImagePropertyOptions = { index: 0, defaultValue: '9999' } imageSourceApi.getImageProperty("BitsPerSample", property, (error: BusinessError, data: string) => { if (error) { console.error('Failed to get the value of the specified attribute key of the image.'); } else { console.info('Succeeded in getting the value of the specified attribute key of the image.'); } }) ``` ## modifyImageProperty(deprecated) modifyImageProperty(key: string, value: string): Promise\ Modifies the value of a property in this image. This API uses a promise to return the result. This API applies only to images that are in JPEG, PNG, or HEIF12+ (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. > **NOTE** > > The property byte length is changed when the **modifyImageProperty** API is called to modify the value of a property. Currently, you can call the API in an ImageSource instance created based on a file descriptor or path, but not an ImageSource instance created based on buffers. > > This API is deprecated since API version 11. You are advised to use [modifyImageProperty](#modifyimageproperty11). **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | ------- | ------ | ---- | ------------ | | key | string | Yes | Name of the property.| | value | string | Yes | New value of the property. | **Return value** | Type | Description | | -------------- | --------------------------- | | Promise\ | Promise that returns no value.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => { imageSourceApi.getImageProperty("ImageWidth").then((width: string) => { console.info(`ImageWidth is :${width}`); }).catch((error: BusinessError) => { console.error('Failed to get the Image Width.'); }) }).catch((error: BusinessError) => { console.error('Failed to modify the Image Width'); }) ``` ## modifyImageProperty(deprecated) modifyImageProperty(key: string, value: string, callback: AsyncCallback\): void Modifies the value of a property in this image. This API uses an asynchronous callback to return the result. This API applies only to images that are in JPEG, PNG, or HEIF12+ (depending on the hardware) format and contain the EXIF information. You can use the **supportedFormats** property to check whether the EXIF read/write operation for images in HEIF format is supported. > **NOTE** > > The property byte length is changed when the **modifyImageProperty** API is called to modify the value of a property. Currently, you can call the API in an ImageSource instance created based on a file descriptor or path, but not an ImageSource instance created based on buffers. > >This API is deprecated since API version 11. You are advised to use [modifyImageProperty](#modifyimageproperty11). **System capability**: SystemCapability.Multimedia.Image.ImageSource **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------- | ---- | ------------------------------ | | key | string | Yes | Name of the property. | | value | string | Yes | New value of the property. | | callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; imageSourceApi.modifyImageProperty("ImageWidth", "120", (err: BusinessError) => { if (err) { console.error(`Failed to modify the Image Width.code is ${err.code}, message is ${err.message}`); } else { console.info('Succeeded in modifying the Image Width.'); } }) ```