openharmony 鸿蒙 capi-drawing-bitmap-h

2026-08-25 浏览 (1)

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

Nametypedef KeywordDescription
OH_Drawing_BitmapFormatOH_Drawing_BitmapFormatDefines the pixel format of a bitmap, including the color type and alpha type.

Functions

NameDescription
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

TypeDescription
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

NameDescription
OH_Drawing_Bitmap* bitmapPointer 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

NameDescription
OH_Drawing_Image_Info* imageInfoPointer to an OH_Drawing_Image_Info object.
void* pixelsPointer 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 rowBytesNumber of bytes in each row of pixels. The value is invalid if it is less than or equal to 0.

Returns

TypeDescription
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

NameDescription
OH_Drawing_Bitmap* bitmapPointer to an OH_Drawing_Bitmap object.
const uint32_t widthWidth of the bitmap to be initialized.
const uint32_t heightHeight of the bitmap to be initialized.
const OH_Drawing_BitmapFormat* bitmapFormatPointer 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

NameDescription
OH_Drawing_Bitmap* bitmapPointer to an OH_Drawing_Bitmap object.

Returns

TypeDescription
uint32_tReturns 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

NameDescription
OH_Drawing_Bitmap* bitmapPointer to an OH_Drawing_Bitmap object.

Returns

TypeDescription
uint32_tReturns 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

NameDescription
OH_Drawing_Bitmap* bitmapPointer to an OH_Drawing_Bitmap object.

Returns

TypeDescription
OH_Drawing_ColorFormatReturns 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

NameDescription
OH_Drawing_Bitmap* bitmapPointer to an OH_Drawing_Bitmap object.

Returns

TypeDescription
OH_Drawing_AlphaFormatReturns 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

NameDescription
OH_Drawing_Bitmap* bitmapPointer to an OH_Drawing_Bitmap object.

Returns

TypeDescription
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

NameDescription
OH_Drawing_Bitmap* bitmapPointer to the OH_Drawing_Bitmap object.
OH_Drawing_Image_Info* imageInfoPointer 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

NameDescription
OH_Drawing_Bitmap* bitmapPointer to the OH_Drawing_Bitmap object.
const OH_Drawing_Image_Info* dstInfoPointer to an OH_Drawing_Image_Info object.
void* dstPixelsPointer to the buffer for storing the pixels read.
size_t dstRowBytesNumber 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 srcXStart X coordinate of the pixel data to read from the bitmap. The value must be less than the width of the bitmap.
int32_t srcYStart Y coordinate of the pixel data to read from the bitmap. The value must be less than the height of the bitmap.

Returns

TypeDescription
boolReturns 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

openharmony 鸿蒙 capi-drawing-brush-h

openharmony 鸿蒙 capi-nativewindow

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/kROMUvNJ