1# @ohos.multimedia.image (Image Processing) (System API) 2<!--Kit: Image Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @aulight02--> 5<!--SE: @liyang_bryan--> 6<!--TSE: @xchaosioda--> 7 8The module provides APIs for image processing. You can use the APIs to create a PixelMap object with specified properties or read image pixel data (even in an area). 9 10> **NOTE** 11> 12> - The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 13> 14> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.multimedia.image (Image Processing)](arkts-apis-image.md). 15 16## Modules to Import 17 18```ts 19import image from '@ohos.multimedia.image'; 20``` 21 22## DecodingOptions<sup>12+</sup> 23 24Describes the image decoding options. 25 26**System API**: This is a system API. 27 28**System capability**: SystemCapability.Multimedia.Image.ImageSource 29 30| Name | Type | Read-Only| Optional| Description | 31| ----------------- | ----------------- | ---- | ---- | ---------------- | 32| resolutionQuality | [ResolutionQuality](#resolutionquality12) | No | Yes | Image quality.| 33 34## ResolutionQuality<sup>12+</sup> 35 36Enumerates the image quality levels. 37 38**System capability**: SystemCapability.Multimedia.Image.Core 39 40| Name | Value | Description | 41| ---------------------------- | ------ | ---------- | 42| LOW | 1 | Low image quality, requiring a short decoding time.<br>This is a system API.| 43| MEDIUM | 2 | Medium image quality, requiring a medium decoding time<br>This is a system API.| 44| HIGH | 3 | High image quality, requiring a long decoding time.<br>This is a system API.| 45 46## image.createPictureByHdrAndSdrPixelMap<sup>20+</sup> 47 48createPictureByHdrAndSdrPixelMap(hdrPixelMap: PixelMap, sdrPixelMap: PixelMap): Promise\<Picture> 49 50Creates a Picture object based on an HDR PixelMap and an SDR PixelMap. The system uses the HDR PixelMap and SDR PixelMap to generate a gainmap. The returned Picture object contains the SDR PixelMap and the generated gainmap, both in RGBA8888 format. This API uses a promise to return the result. 51 52**System API**: This is a system API. 53 54**System capability**: SystemCapability.Multimedia.Image.Core 55 56**Parameters** 57 58| Name | Type | Mandatory| Description | 59| ------------ | ------------------- | ---- | ---------------- | 60| hdrPixelmap | [PixelMap](arkts-apis-image-PixelMap.md#interface-pixelmap) | Yes | HDR PixelMap, with 16-bit or 10-bit depth, in FP16/RGBA1010102/YCBCR_P010 format, and BT2020_HLG color space.| 61| sdrPixelmap | [PixelMap](arkts-apis-image-PixelMap.md#interface-pixelmap) | Yes | SDR PixelMap, with 8-bit depth, in RGBA8888/NV21 format, and P3 color space.| 62 63**Returns** 64 65| Type | Description | 66| ------------------ | ----------------- | 67|Promise\<[Picture](arkts-apis-image-Picture.md#interface-picture)> | Picture object that contains the SDR PixelMap and gainmap, both in RGBA8888 format.| 68 69**Error codes** 70 71For details about the error codes, see [Image Error Codes](errorcode-image.md). 72 73| Error Code| Error Message | 74| -------- | ------------------------------------------------------------ | 75| 7600201 | Unsupported operation. HdrPixelMap's PixelMapFormat is not RGBA_F16\RGBA_1010102\YCBCR_P010, or its color space is not BT2020_HLG. Or sdrPixelMap's PixelMapFormat is not RGBA_8888\NV21\NV12, or its color space is not P3. | 76 77**Example** 78 79```ts 80import image from '@ohos.multimedia.image'; 81import fs from '@ohos.file.fs'; 82import { BusinessError } from '@ohos.base'; 83 84async function CreatePictureTest(context: Context) { 85 const resourceMgr = context.resourceManager; 86 const rawFile = await resourceMgr.getRawFileContent("test.jpg"); // SDR 87 let imageSource: image.ImageSource = image.createImageSource(rawFile); 88 let options1: image.DecodingOptions = { 89 desiredDynamicRange : image.DecodingDynamicRange.SDR, 90 } 91 let options2: image.DecodingOptions = { 92 desiredDynamicRange : image.DecodingDynamicRange.HDR, // Decode an SDR PixelMap into an HDR PixelMap using AIHDR. 93 } 94 let sdrPixelMap = await imageSource.createPixelMap(options1); 95 let hdrPixelMap = await imageSource.createPixelMap(options2); 96 97 // Obtain the gainmap generated and encode the gainmap. 98 let picture: image.Picture = await image.createPictureByHdrAndSdrPixelMap(hdrPixelMap, sdrPixelMap); 99 if (picture != null) { 100 console.info('Create picture succeeded'); 101 } else { 102 console.error('Create picture failed'); 103 } 104 const imagePackerApi = image.createImagePacker(); 105 let packOpts : image.PackingOption = { format : "image/jpeg", quality: 98}; 106 packOpts.desiredDynamicRange = image.PackingDynamicRange.AUTO; 107 const path: string = context.filesDir + "/hdr-test.jpg"; 108 let file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); 109 imagePackerApi.packToFile(picture, file.fd, packOpts).then(() => { 110 }).catch((error : BusinessError) => { 111 console.error('Failed to pack the image. And the error is: ' + error); 112 }) 113} 114``` 115