鸿蒙OS开发文档 鸿蒙OS《Native API参考》

2024-02-25 开发教程 鸿蒙OS开发文档 匿名 3

Image

Overview

Provides access to pixel data and pixel map information.

Since:

3

Version:

1.0

Summary

Files

File NameDescription
image_pixel_map.hDeclares functions for you to lock and access or unlock pixel data, and obtain the width and height of a pixel map.

Data Structures

Data Structure NameDescription
OhosPixelMapInfoDefines pixel map information.

Enumerations

Enumeration NameDescription
{ OHOS_IMAGE_RESULT_SUCCESS = 0, OHOS_IMAGE_RESULT_BAD_PARAMETER = -1, OHOS_IMAGE_RESULT_JNI_EXCEPTION = -2 }Enumerates the result codes that may be returned by a function.
{ OHOS_PIXEL_MAP_FORMAT_NONE = 0, OHOS_PIXEL_MAP_FORMAT_RGBA_8888 = 3, OHOS_PIXEL_MAP_FORMAT_RGB_565 = 2 }Enumerates pixel formats.

Functions

Function NameDescription
GetImageInfo (JNIEnv *env, jobject pixelMapObject, OhosPixelMapInfo &info)int32_tObtains information about a given PixelMap and stores the information in a OhosPixelMapInfo structure.
AccessPixels (JNIEnv *env, jobject pixelMapObject, void **addrPtr)int32_tObtains the memory address of a given PixelMap object and locks the memory.
UnAccessPixels (JNIEnv *env, jobject pixelMapObject)int32_tUnlocks the memory storing the pixel data of a given PixelMap to balance a successful call to AccessPixels.

Details

Enumeration Type Documentation

anonymous enum

anonymous enum

Description:

Enumerates the result codes that may be returned by a function.

EnumeratorDescription
OHOS_IMAGE_RESULT_SUCCESSSuccess result
OHOS_IMAGE_RESULT_BAD_PARAMETERInvalid parameters
OHOS_IMAGE_RESULT_JNI_EXCEPTIONJNI exception

anonymous enum

anonymous enum

Description:

Enumerates pixel formats.

EnumeratorDescription
OHOS_PIXEL_MAP_FORMAT_NONEUnknown format
OHOS_PIXEL_MAP_FORMAT_RGBA_888832-bit RGBA. Components R, G, B, and A each occupies 8 bits and are stored from the higher-order to the lower-order bits.
OHOS_PIXEL_MAP_FORMAT_RGB_56516-bit RGB. Only the R, G, and B components are encoded from the higher-order to the lower-order bits: red is stored with 5 bits of precision, green is stored with 6 bits of precision, and blue is stored with 5 bits of precision.

Function Documentation

AccessPixels()

int32_t AccessPixels (JNIEnv * env, jobject pixelMapObject, void ** addrPtr )

Description:

Obtains the memory address of a given PixelMap object and locks the memory.

If this function call is successful, *addrPtr is set to the memory address. After accessing the pixel data, you must use UnAccessPixels to unlock the memory. Otherwise, resources cannot be released. After the memory is unlocked, it can be invalid and should not be accessed.

Parameters:

NameDescription
envIndicates the pointer to the JNI environment.
pixelMapObjectIndicates the Java PixelMap object.
addrPtrIndicates the double pointer to the memory address.

See also:

UnAccessPixels

Returns:

Returns OHOS_IMAGE_RESULT_SUCCESS if the operation is successful; returns other result codes if the operation fails.

GetImageInfo()

int32_t GetImageInfo (JNIEnv * env, jobject pixelMapObject, OhosPixelMapInfo & info )

Description:

Obtains information about a given PixelMap and stores the information in a OhosPixelMapInfo structure.

Parameters:

NameDescription
envIndicates the pointer to the JNI environment.
pixelMapObjectIndicates the Java PixelMap object.
infoIndicates the pointer to the pixel map information to obtain. For details, see OhosPixelMapInfo.

Returns:

Returns 0 if the information is obtained and stored in the structure; returns result codes if the operation fails. OhosPixelMapInfo 3 1.0

UnAccessPixels()

int32_t UnAccessPixels (JNIEnv * env, jobject pixelMapObject )

Description:

Unlocks the memory storing the pixel data of a given PixelMap to balance a successful call to AccessPixels.

Parameters:

NameDescription
envIndicates the pointer to the JNI environment.
pixelMapObjectIndicates the Java PixelMap object.

Returns:

Returns OHOS_IMAGE_RESULT_SUCCESS if the operation is successful; returns other result codes if the operation fails.

See also:

AccessPixels