1e41f4b71Sopenharmony_ci# Using PixelMap to Transform Images 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciImage processing refers to a series of operations performed on the pixel map, such as obtaining image information, cropping, scaling, translating, rotating, flipping, setting opacity, and reading and writing pixel data. These operations can be classified into image transformation and [PixelMap operation](image-pixelmap-operation.md). This topic describes the image transformation operations that you can perform. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci## How to Develop 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciRead [Image](../../reference/apis-image-kit/js-apis-image.md#pixelmap7) for APIs related to image transformation. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci1. Complete [image decoding](image-decoding.md) and obtain a **PixelMap** object. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci2. Obtain image information. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci ```ts 14e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 15e41f4b71Sopenharmony_ci // Obtain the image size. 16e41f4b71Sopenharmony_ci pixelMap.getImageInfo().then( (info : image.ImageInfo) => { 17e41f4b71Sopenharmony_ci console.info('info.width = ' + info.size.width); 18e41f4b71Sopenharmony_ci console.info('info.height = ' + info.size.height); 19e41f4b71Sopenharmony_ci }).catch((err : BusinessError) => { 20e41f4b71Sopenharmony_ci console.error("Failed to obtain the image pixel map information.And the error is: " + err); 21e41f4b71Sopenharmony_ci }); 22e41f4b71Sopenharmony_ci ``` 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci3. Perform image transformation. 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci Original image: 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci  29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci - Crop the image. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci ```ts 33e41f4b71Sopenharmony_ci // x: x-axis coordinate of the start point for cropping (0). 34e41f4b71Sopenharmony_ci // y: y-axis coordinate of the start point for cropping (0). 35e41f4b71Sopenharmony_ci // height: height after cropping (400), cropping from top to bottom. 36e41f4b71Sopenharmony_ci // width: width after cropping (400), cropping from left to right. 37e41f4b71Sopenharmony_ci pixelMap.crop({x: 0, y: 0, size: { height: 400, width: 400 } }); 38e41f4b71Sopenharmony_ci ``` 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci  41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci - Scale the image. 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci ```ts 45e41f4b71Sopenharmony_ci // The width of the image after scaling is 0.5 of the original width. 46e41f4b71Sopenharmony_ci // The height of the image after scaling is 0.5 of the original height. 47e41f4b71Sopenharmony_ci pixelMap.scale(0.5, 0.5); 48e41f4b71Sopenharmony_ci ``` 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci  51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci - Translate the image. 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci ```ts 55e41f4b71Sopenharmony_ci // Translate the image by 100 units downwards. 56e41f4b71Sopenharmony_ci // Translate the image by 100 units rightwards. 57e41f4b71Sopenharmony_ci pixelMap.translate(100, 100); 58e41f4b71Sopenharmony_ci ``` 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci  61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci - Rotate the image. 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci ```ts 65e41f4b71Sopenharmony_ci // Rate the image clockwise by 90°. 66e41f4b71Sopenharmony_ci pixelMap.rotate(90); 67e41f4b71Sopenharmony_ci ``` 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci  70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci - Flip the image. 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci ```ts 74e41f4b71Sopenharmony_ci // Flip the image vertically. 75e41f4b71Sopenharmony_ci pixelMap.flip(false, true); 76e41f4b71Sopenharmony_ci ``` 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci  79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci ```ts 81e41f4b71Sopenharmony_ci // Flip the image horizontally. 82e41f4b71Sopenharmony_ci pixelMap.flip(true, false); 83e41f4b71Sopenharmony_ci ``` 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci  86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci - Set the opacity of the image. 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci ```ts 90e41f4b71Sopenharmony_ci // Set the opacity to 0.5. 91e41f4b71Sopenharmony_ci pixelMap.opacity(0.5); 92e41f4b71Sopenharmony_ci ``` 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci  95