drawing_bitmap.h
Overview
This file declares the functions related to the bitmap in the drawing module.
Sample: NDKAPIDrawing (API Version 20)
File to include: <native_drawing/drawing_bitmap.h>
Library: libnative_drawing.so
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Related module: Drawing
Summary
Structs
| Name | typedef Keyword | Description |
|---|---|---|
| OH_Drawing_BitmapFormat | OH_Drawing_BitmapFormat | Defines the pixel format of a bitmap, including the color type and alpha type. |
Functions
| Name | Description |
|---|---|
| OH_Drawing_Bitmap* OH_Drawing_BitmapCreate(void) | Creates an OH_Drawing_Bitmap object. |
| void OH_Drawing_BitmapDestroy(OH_Drawing_Bitmap* bitmap) | Destroys an OH_Drawing_Bitmap object and reclaims the memory occupied by the object. |
| OH_Drawing_Bitmap* OH_Drawing_BitmapCreateFromPixels(OH_Drawing_Image_Info* imageInfo, void* pixels, uint32_t rowBytes) | Creates an OH_Drawing_Bitmap object, with the address of the memory for storing the bitmap pixels set to the memory address that you applied for. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If either imageInfo or pixels is NULL or rowBytes is 0, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| void OH_Drawing_BitmapBuild(OH_Drawing_Bitmap* bitmap,const uint32_t width, const uint32_t height, const OH_Drawing_BitmapFormat* bitmapFormat) | Initializes the width and height of a bitmap and sets the pixel format for the bitmap. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If either bitmap or bitmapFormat is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| uint32_t OH_Drawing_BitmapGetWidth(OH_Drawing_Bitmap* bitmap) | Obtains the width of a bitmap. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| uint32_t OH_Drawing_BitmapGetHeight(OH_Drawing_Bitmap* bitmap) | Obtains the height of a bitmap. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| OH_Drawing_ColorFormat OH_Drawing_BitmapGetColorFormat(OH_Drawing_Bitmap* bitmap) | Obtains the pixel format of a bitmap. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| OH_Drawing_AlphaFormat OH_Drawing_BitmapGetAlphaFormat(OH_Drawing_Bitmap* bitmap) | Obtains the alpha component of a bitmap. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| void* OH_Drawing_BitmapGetPixels(OH_Drawing_Bitmap* bitmap) | Obtains the pixel address of a bitmap. You can use this address to obtain the pixel data of the bitmap. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| void OH_Drawing_BitmapGetImageInfo(OH_Drawing_Bitmap* bitmap, OH_Drawing_Image_Info* imageInfo) | Obtains the image information of a bitmap. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If either bitmap or imageInfo is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
| bool OH_Drawing_BitmapReadPixels(OH_Drawing_Bitmap* bitmap, const OH_Drawing_Image_Info* dstInfo,void* dstPixels, size_t dstRowBytes, int32_t srcX, int32_t srcY) | Reads pixels of a rectangle in a bitmap to the specified buffer. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If any of bitmap, dstInfo, and dstPixels is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. |
Function Description
OH_Drawing_BitmapCreate()
OH_Drawing_Bitmap* OH_Drawing_BitmapCreate(void)
Description
Creates an OH_Drawing_Bitmap object.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Returns
| Type | Description |
|---|---|
| OH_Drawing_Bitmap* | Returns the pointer to the OH_Drawing_Bitmap object created. |
OH_Drawing_BitmapDestroy()
void OH_Drawing_BitmapDestroy(OH_Drawing_Bitmap* bitmap)
Description
Destroys an OH_Drawing_Bitmap object and reclaims the memory occupied by the object.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Bitmap* bitmap | Pointer to an OH_Drawing_Bitmap object. |
OH_Drawing_BitmapCreateFromPixels()
OH_Drawing_Bitmap* OH_Drawing_BitmapCreateFromPixels(OH_Drawing_Image_Info* imageInfo, void* pixels, uint32_t rowBytes)
Description
Creates an OH_Drawing_Bitmap object, with the address of the memory for storing the bitmap pixels set to the memory address that you applied for.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either imageInfo or pixels is NULL or rowBytes is 0, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Image_Info* imageInfo | Pointer to an OH_Drawing_Image_Info object. |
| void* pixels | Pointer to the start address of the memory for storing the bitmap pixels. You need to apply for the memory and ensure its validity. |
| uint32_t rowBytes | Number of bytes in each row of pixels. The value is invalid if it is less than or equal to 0. |
Returns
| Type | Description |
|---|---|
| OH_Drawing_Bitmap* | Returns a pointer to the OH_Drawing_Bitmap object created. |
OH_Drawing_BitmapBuild()
void OH_Drawing_BitmapBuild(OH_Drawing_Bitmap* bitmap,const uint32_t width, const uint32_t height, const OH_Drawing_BitmapFormat* bitmapFormat)
Description
Initializes the width and height of a bitmap and sets the pixel format for the bitmap.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either bitmap or bitmapFormat is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Bitmap* bitmap | Pointer to an OH_Drawing_Bitmap object. |
| const uint32_t width | Width of the bitmap to be initialized. |
| const uint32_t height | Height of the bitmap to be initialized. |
| const OH_Drawing_BitmapFormat* bitmapFormat | Pointer to the pixel format of the bitmap to be initialized, including the pixel color type and alpha type. |
OH_Drawing_BitmapGetWidth()
uint32_t OH_Drawing_BitmapGetWidth(OH_Drawing_Bitmap* bitmap)
Description
Obtains the width of a bitmap.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Bitmap* bitmap | Pointer to an OH_Drawing_Bitmap object. |
Returns
| Type | Description |
|---|---|
| uint32_t | Returns the width. |
OH_Drawing_BitmapGetHeight()
uint32_t OH_Drawing_BitmapGetHeight(OH_Drawing_Bitmap* bitmap)
Description
Obtains the height of a bitmap.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Bitmap* bitmap | Pointer to an OH_Drawing_Bitmap object. |
Returns
| Type | Description |
|---|---|
| uint32_t | Returns the height. |
OH_Drawing_BitmapGetColorFormat()
OH_Drawing_ColorFormat OH_Drawing_BitmapGetColorFormat(OH_Drawing_Bitmap* bitmap)
Description
Obtains the pixel format of a bitmap.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Bitmap* bitmap | Pointer to an OH_Drawing_Bitmap object. |
Returns
| Type | Description |
|---|---|
| OH_Drawing_ColorFormat | Returns the pixel format. For details about the supported formats, see OH_Drawing_ColorFormat. |
OH_Drawing_BitmapGetAlphaFormat()
OH_Drawing_AlphaFormat OH_Drawing_BitmapGetAlphaFormat(OH_Drawing_Bitmap* bitmap)
Description
Obtains the alpha component of a bitmap.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Bitmap* bitmap | Pointer to an OH_Drawing_Bitmap object. |
Returns
| Type | Description |
|---|---|
| OH_Drawing_AlphaFormat | Returns the alpha component. For details about the supported formats, see OH_Drawing_AlphaFormat. |
OH_Drawing_BitmapGetPixels()
void* OH_Drawing_BitmapGetPixels(OH_Drawing_Bitmap* bitmap)
Description
Obtains the pixel address of a bitmap. You can use this address to obtain the pixel data of the bitmap.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 8
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Bitmap* bitmap | Pointer to an OH_Drawing_Bitmap object. |
Returns
| Type | Description |
|---|---|
| void* | Returns the pixel address. |
OH_Drawing_BitmapGetImageInfo()
void OH_Drawing_BitmapGetImageInfo(OH_Drawing_Bitmap* bitmap, OH_Drawing_Image_Info* imageInfo)
Description
Obtains the image information of a bitmap.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either bitmap or imageInfo is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Bitmap* bitmap | Pointer to the OH_Drawing_Bitmap object. |
| OH_Drawing_Image_Info* imageInfo | Pointer to an OH_Drawing_Image_Info object. |
OH_Drawing_BitmapReadPixels()
bool OH_Drawing_BitmapReadPixels(OH_Drawing_Bitmap* bitmap, const OH_Drawing_Image_Info* dstInfo,void* dstPixels, size_t dstRowBytes, int32_t srcX, int32_t srcY)
Description
Reads pixels of a rectangle in a bitmap to the specified buffer.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If any of bitmap, dstInfo, and dstPixels is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing
Since: 12
Parameters
| Name | Description |
|---|---|
| OH_Drawing_Bitmap* bitmap | Pointer to the OH_Drawing_Bitmap object. |
| const OH_Drawing_Image_Info* dstInfo | Pointer to an OH_Drawing_Image_Info object. |
| void* dstPixels | Pointer to the buffer for storing the pixels read. |
| size_t dstRowBytes | Number of bytes in each row of the pixel data read. The value must be greater than or equal to the minimum number of bytes in each row in the OH_Drawing_Image_Info object. |
| int32_t srcX | Start X coordinate of the pixel data to read from the bitmap. The value must be less than the width of the bitmap. |
| int32_t srcY | Start Y coordinate of the pixel data to read from the bitmap. The value must be less than the height of the bitmap. |
Returns
| Type | Description |
|---|---|
| bool | Returns true if the pixels are read; returns false otherwise. |
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 capi-drawing-gpu-context-h
openharmony 鸿蒙 capi-drawing-nativepixelmap-
openharmony 鸿蒙 capi-nativevsync-oh-nativevsync-expectedraterange
openharmony 鸿蒙 capi-drawing-oh-drawing-brush
openharmony 鸿蒙 capi-drawing-oh-drawing-image-info
openharmony 鸿蒙 capi-drawing-text-linetypography-h
openharmony 鸿蒙 capi-oh-nativeimage-oh-nativeimage
openharmony 鸿蒙 capi-drawing-typeface-h