We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesGraphicsArkGraphics 2DC APIsHeader Filesdrawing_bitmap.h

drawing_bitmap.h

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

Overview

This file declares the functions related to the bitmap in the drawing module.

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

Expand
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

Expand
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()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. OH_Drawing_Bitmap* OH_Drawing_BitmapCreate(void)

Description

Creates an OH_Drawing_Bitmap object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Returns

Expand
Type Description
OH_Drawing_Bitmap* Returns the pointer to the OH_Drawing_Bitmap object created.

OH_Drawing_BitmapDestroy()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
Name Description
OH_Drawing_Bitmap* bitmap Pointer to an OH_Drawing_Bitmap object.

OH_Drawing_BitmapCreateFromPixels()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
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

Expand
Type Description
OH_Drawing_Bitmap* Returns a pointer to the OH_Drawing_Bitmap object created.

OH_Drawing_BitmapBuild()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
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()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
Name Description
OH_Drawing_Bitmap* bitmap Pointer to an OH_Drawing_Bitmap object.

Returns

Expand
Type Description
uint32_t Returns the width.

OH_Drawing_BitmapGetHeight()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
Name Description
OH_Drawing_Bitmap* bitmap Pointer to an OH_Drawing_Bitmap object.

Returns

Expand
Type Description
uint32_t Returns the height.

OH_Drawing_BitmapGetColorFormat()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
Name Description
OH_Drawing_Bitmap* bitmap Pointer to an OH_Drawing_Bitmap object.

Returns

Expand
Type Description
OH_Drawing_ColorFormat Returns the pixel format. For details about the supported formats, see OH_Drawing_ColorFormat.

OH_Drawing_BitmapGetAlphaFormat()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
Name Description
OH_Drawing_Bitmap* bitmap Pointer to an OH_Drawing_Bitmap object.

Returns

Expand
Type Description
OH_Drawing_AlphaFormat Returns the alpha component. For details about the supported formats, see OH_Drawing_AlphaFormat.

OH_Drawing_BitmapGetPixels()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
Name Description
OH_Drawing_Bitmap* bitmap Pointer to an OH_Drawing_Bitmap object.

Returns

Expand
Type Description
void* Returns the pixel address.

OH_Drawing_BitmapGetImageInfo()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
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()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
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

Expand
Type Description
bool Returns true if the pixels are read; returns false otherwise.