openharmony 鸿蒙 capi-drawing-canvas-h

2026-08-25 浏览 (1)

drawing_canvas.h

Overview

This file declares the functions related to the canvas in the drawing module.
By default, the canvas has a black brush with anti-aliasing enabled and without any other style. This brush takes effect only when no brush or pen is proactively set in the canvas.

Sample: NDKAPIDrawing (API Version 20)

File to include: <native_drawing/drawing_canvas.h>

Library: libnative_drawing.so

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Related module: Drawing

Summary

Enums

Nametypedef KeywordDescription
OH_Drawing_SrcRectConstraintOH_Drawing_SrcRectConstraintDefines an enum for the constraint types of the source rectangle.
OH_Drawing_PointModeOH_Drawing_PointModeDefines an enum for the modes of drawing multiple points. The modes include discrete points, line segments, and open polygons.
OH_Drawing_CanvasClipOpOH_Drawing_CanvasClipOpDefines an enum for the canvas clipping modes.
OH_Drawing_CanvasShadowFlagsOH_Drawing_CanvasShadowFlagsDefines an enum for the shadow flags.
OH_Drawing_VertexModeOH_Drawing_VertexModeDefines an enum for the modes of interpreting the geometry of a given vertex.

Functions

NameDescription
OH_Drawing_Canvas* OH_Drawing_CanvasCreate(void)Creates an OH_Drawing_Canvas object.
OH_Drawing_Canvas* OH_Drawing_CanvasCreateWithPixelMap(OH_Drawing_PixelMap* pixelMap)Binds a pixel map to a canvas so that the content drawn on the canvas is output to the pixel map. (This process is called CPU rendering.) A canvas bound to a pixel map is a non-recording canvas.
You should unbind the pixel map object by calling OH_Drawing_PixelMapDissolve after the canvas object is destroyed.
void OH_Drawing_CanvasDestroy(OH_Drawing_Canvas* canvas)Destroys an OH_Drawing_Canvas object and reclaims the memory occupied by the object.
void OH_Drawing_CanvasBind(OH_Drawing_Canvas* canvas, OH_Drawing_Bitmap* bitmap)Binds a bitmap to a canvas so that the content drawn on the canvas is output to the bitmap. (This process is called CPU rendering.) A canvas bound to a bitmap is a non-recording canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasAttachPen(OH_Drawing_Canvas* canvas, const OH_Drawing_Pen* pen)Attaches a pen to a canvas so that the canvas can use the style and color of the pen to outline a shape. If the pen effect changes after this function is called, you must call the function again to use the new effect in the subsequent drawing.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDetachPen(OH_Drawing_Canvas* canvas)Detaches the pen from a canvas so that the canvas can no longer use the style and color of the pen to outline a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasAttachBrush(OH_Drawing_Canvas* canvas, const OH_Drawing_Brush* brush)Attaches a brush to a canvas so that the canvas can use the style and color of the brush to fill in a shape. If the brush effect changes after this function is called, you must call the function again to use the new effect in the subsequent drawing.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDetachBrush(OH_Drawing_Canvas* canvas)Detaches the brush from a canvas so that the canvas can no longer use the previously set brush to fill in a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasSave(OH_Drawing_Canvas* canvas)Saves the current canvas status (canvas matrix) to the top of the stack. This function works with OH_Drawing_CanvasRestore.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasSaveLayer(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect, const OH_Drawing_Brush* brush)Saves the matrix and cropping region, and allocates a bitmap for subsequent drawing. If you call OH_Drawing_CanvasRestore, changes made to the matrix and clipping region are discarded, and the bitmap is drawn.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasRestore(OH_Drawing_Canvas* canvas)Restores the canvas status (canvas matrix) saved on the top of the stack.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
uint32_t OH_Drawing_CanvasGetSaveCount(OH_Drawing_Canvas* canvas)Obtains the number of canvas statuses (canvas matrices) saved in the stack.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasRestoreToCount(OH_Drawing_Canvas* canvas, uint32_t saveCount)Restores to a given number of canvas statuses (canvas matrices).
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDrawLine(OH_Drawing_Canvas* canvas, float x1, float y1, float x2, float y2)Draws a line segment.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDrawPath(OH_Drawing_Canvas* canvas, const OH_Drawing_Path* path)Draws a path.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or path is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
OH_Drawing_ErrorCode OH_Drawing_CanvasDrawPixelMapNine(OH_Drawing_Canvas* canvas, OH_Drawing_PixelMap* pixelMap,const OH_Drawing_Rect* center, const OH_Drawing_Rect* dst, OH_Drawing_FilterMode mode)Splits a pixel map into nine sections using two horizontal and two vertical lines: four edge sections, four corner sections, and a central section.
If the four corner sections are smaller than the target rectangle, they will be drawn in the target rectangle without scaling. Otherwise, they will be scaled to fit the target rectangle.
Any remaining space will be filled by stretching or compressing the other five sections to cover the entire target rectangle.
void OH_Drawing_CanvasDrawPixelMapRect(OH_Drawing_Canvas* canvas, OH_Drawing_PixelMap* pixelMap,const OH_Drawing_Rect* src, const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions* samplingOptions)Draws a portion of a pixel map onto a specified area of the canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If one of canvas, pixelMap, or dst is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDrawBackground(OH_Drawing_Canvas* canvas, const OH_Drawing_Brush* brush)Draws a background filled with a brush.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDrawRegion(OH_Drawing_Canvas* canvas, const OH_Drawing_Region* region)Draws a region.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or region is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
OH_Drawing_ErrorCode OH_Drawing_CanvasDrawPoint(OH_Drawing_Canvas* canvas, const OH_Drawing_Point2D* point)Draws a point.
void OH_Drawing_CanvasDrawPoints(OH_Drawing_Canvas* canvas, OH_Drawing_PointMode mode,uint32_t count, const OH_Drawing_Point2D* point2D)Draws multiple points. You can draw a single point, a line segment, or an open polygon.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or point2D is NULL, or count is 0, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. If mode is not within the enumerated range, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.
void OH_Drawing_CanvasDrawBitmap(OH_Drawing_Canvas* canvas, const OH_Drawing_Bitmap* bitmap, float left, float top)Draws a bitmap. A bitmap, also referred to as a dot matrix image, a pixel map image, or a grid image, includes single points called pixels (image elements).
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDrawBitmapRect(OH_Drawing_Canvas* canvas, const OH_Drawing_Bitmap* bitmap,const OH_Drawing_Rect* src, const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions* samplingOptions)Draws a portion of a bitmap onto a specified area of the canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If one of canvas, bitmap, or dst is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDrawRect(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect)Draws a rectangle.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or OH_Drawing_Rect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDrawCircle(OH_Drawing_Canvas* canvas, const OH_Drawing_Point* point, float radius)Draws a circle. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If either canvas or point is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If radius is less than or equal to 0, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.
OH_Drawing_ErrorCode OH_Drawing_CanvasDrawColor(OH_Drawing_Canvas* canvas, uint32_t color,OH_Drawing_BlendMode blendMode)Fills the entire canvas with the specified color and blend mode.
void OH_Drawing_CanvasDrawOval(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect)Draws an oval. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If either canvas or rect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDrawArc(OH_Drawing_Canvas* canvas,const OH_Drawing_Rect* rect, float startAngle, float sweepAngle)Draws an arc. If the absolute value of the sweep angle exceeds 360 degrees, an ellipse is drawn.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or rect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
OH_Drawing_ErrorCode OH_Drawing_CanvasDrawArcWithCenter(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect,float startAngle, float sweepAngle, bool useCenter)Draws an arc. It enables you to define the starting angle, sweep angle, and whether the arc's endpoints should connect to its center.
void OH_Drawing_CanvasDrawRoundRect(OH_Drawing_Canvas* canvas, const OH_Drawing_RoundRect* roundRect)Draws a rounded rectangle. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If either canvas or roundRect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
OH_Drawing_ErrorCode OH_Drawing_CanvasDrawNestedRoundRect(OH_Drawing_Canvas* canvas, const OH_Drawing_RoundRect* outer,const OH_Drawing_RoundRect* inner)Draws two nested rounded rectangles. The outer rectangle boundary must contain the inner rectangle boundary. Otherwise, there is no drawing effect.
OH_Drawing_ErrorCode OH_Drawing_CanvasDrawSingleCharacter(OH_Drawing_Canvas* canvas, const char* str,const OH_Drawing_Font* font, float x, float y)Draws a single character. If the typeface of the current font does not support the character to draw, the system typeface is used to draw the character.
void OH_Drawing_CanvasDrawTextBlob(OH_Drawing_Canvas* canvas, const OH_Drawing_TextBlob* textBlob, float x, float y)Draws a text blob. If the typeface used to construct OH_Drawing_TextBlob does not support a character, that character will not be drawn.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or textBlob is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasClipRect(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect,OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias)Clips a rectangle.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or rect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If clipOp is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.
void OH_Drawing_CanvasClipRoundRect(OH_Drawing_Canvas* canvas, const OH_Drawing_RoundRect* roundRect,OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias)Clips a rounded rectangle.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or roundRect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If clipOp is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.
void OH_Drawing_CanvasClipPath(OH_Drawing_Canvas* canvas, const OH_Drawing_Path* path,OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias)Clips a path.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or path is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If clipOp is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.
OH_Drawing_ErrorCode OH_Drawing_CanvasClipRegion(OH_Drawing_Canvas* canvas, const OH_Drawing_Region* region,OH_Drawing_CanvasClipOp clipOp)Clips a rectangle.
void OH_Drawing_CanvasRotate(OH_Drawing_Canvas* canvas, float degrees, float px, float py)Rotates a canvas by a given angle. A positive value indicates a clockwise rotation, and a negative value indicates a counterclockwise rotation.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasTranslate(OH_Drawing_Canvas* canvas, float dx, float dy)Translates a canvas by a given distance.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasScale(OH_Drawing_Canvas* canvas, float sx, float sy)Scales a canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasSkew(OH_Drawing_Canvas* canvas, float sx, float sy)Skews a canvas. This function premultiplies the current canvas matrix by a skew transformation matrix and applies the resulting matrix to the canvas. The skew transformation matrix is as follows:
|1 sx 0|
|sy 1 0|
|0 0 1|.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
int32_t OH_Drawing_CanvasGetWidth(OH_Drawing_Canvas* canvas)Obtains the canvas width.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
int32_t OH_Drawing_CanvasGetHeight(OH_Drawing_Canvas* canvas)Obtains the canvas height.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasGetLocalClipBounds(OH_Drawing_Canvas* canvas, OH_Drawing_Rect* rect)Obtains the bounds of the cropping region of the canvas. This function cannot be used for a canvas of the recording type.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or rect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasGetTotalMatrix(OH_Drawing_Canvas* canvas, OH_Drawing_Matrix* matrix)Obtains the 3x3 matrix of a canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or matrix is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasConcatMatrix(OH_Drawing_Canvas* canvas, OH_Drawing_Matrix* matrix)Preconcats the existing matrix of the canvas with the passed-in matrix. The drawing operation triggered before this API is called is not affected.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or matrix is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDrawShadow(OH_Drawing_Canvas* canvas, OH_Drawing_Path* path, OH_Drawing_Point3D planeParams,OH_Drawing_Point3D devLightPos, float lightRadius, uint32_t ambientColor, uint32_t spotColor,OH_Drawing_CanvasShadowFlags flag)Draws a spot shadow and uses a given path to outline the ambient shadow.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or path is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If flag is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.
void OH_Drawing_CanvasClear(OH_Drawing_Canvas* canvas, uint32_t color)Clears a canvas by using a given color.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasSetMatrix(OH_Drawing_Canvas* canvas, OH_Drawing_Matrix* matrix)Sets the matrix status for a canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or matrix is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasResetMatrix(OH_Drawing_Canvas* canvas)Resets the matrix of this canvas to an identity matrix.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDrawImageRectWithSrc(OH_Drawing_Canvas* canvas, const OH_Drawing_Image* image,const OH_Drawing_Rect* src, const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions* samplingOptions,OH_Drawing_SrcRectConstraint srcRectConstraint)Draws a portion of an image onto a specified area of the canvas. The area selected by the source rectangle is scaled and translated to the destination rectangle.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If one of canvas, image, src, or dst is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDrawImageRect(OH_Drawing_Canvas* canvas, OH_Drawing_Image* image,OH_Drawing_Rect* rect, OH_Drawing_SamplingOptions* samplingOptions)Draws an image onto a specified area of the canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If one of canvas, image, or dst is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_CanvasDrawVertices(OH_Drawing_Canvas* canvas, OH_Drawing_VertexMode vertexMmode,int32_t vertexCount, const OH_Drawing_Point2D* positions, const OH_Drawing_Point2D* texs,const uint32_t* colors, int32_t indexCount, const uint16_t* indices, OH_Drawing_BlendMode mode)Draws a triangular grid described by a vertex array.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or positions is NULL, vertexCount is less than 3, or indexCount is less than 3 but not 0, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If either vertexMmode or mode is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.
bool OH_Drawing_CanvasReadPixels(OH_Drawing_Canvas* canvas, OH_Drawing_Image_Info* imageInfo,void* dstPixels, uint32_t dstRowBytes, int32_t srcX, int32_t srcY)Copies pixel data from a canvas to a specified address. This function cannot be used for a canvas of the recording type.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If one of canvas, imageInfo, or dstPixels is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
bool OH_Drawing_CanvasReadPixelsToBitmap(OH_Drawing_Canvas* canvas,OH_Drawing_Bitmap* bitmap, int32_t srcX, int32_t srcY)Copies pixel data from a canvas to an image. This function cannot be used for a canvas of the recording type.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
OH_Drawing_ErrorCode OH_Drawing_CanvasIsClipEmpty(OH_Drawing_Canvas* canvas, bool* isClipEmpty)Checks whether the region that can be drawn is empty after clipping.
OH_Drawing_ErrorCode OH_Drawing_CanvasGetImageInfo(OH_Drawing_Canvas* canvas, OH_Drawing_Image_Info* imageInfo)Obtains the image information of a canvas.
OH_Drawing_ErrorCode OH_Drawing_CanvasDrawRecordCmd(OH_Drawing_Canvas* canvas, OH_Drawing_RecordCmd* recordCmd)Draws an OH_Drawing_RecordCmd object.
OH_Drawing_ErrorCode OH_Drawing_CanvasDrawRecordCmdNesting(OH_Drawing_Canvas* canvas, OH_Drawing_RecordCmd* recordCmd)Draws an OH_Drawing_RecordCmd object. This API supports nesting.
Specifically, it can use the canvas object generated by OH_Drawing_RecordCmdUtilsBeginRecording as the input parameter. However, multi-layer nesting is not recommended because it affects performance.
OH_Drawing_ErrorCode OH_Drawing_CanvasQuickRejectPath(OH_Drawing_Canvas* canvas, const OH_Drawing_Path* path,bool* quickReject)Checks whether the path is not intersecting with the canvas area. The canvas area includes its boundaries.
OH_Drawing_ErrorCode OH_Drawing_CanvasQuickRejectRect(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect,bool* quickReject)Checks whether the rectangle is not intersecting with the canvas area. The canvas area includes its boundaries.
OH_Drawing_ErrorCode OH_Drawing_CanvasDrawPixelMapRectConstraint(OH_Drawing_Canvas* canvas,OH_Drawing_PixelMap* pixelMap, const OH_Drawing_Rect* src, const OH_Drawing_Rect* dst,const OH_Drawing_SamplingOptions* samplingOptions, OH_Drawing_SrcRectConstraint constraint)Draws a portion of a pixel map onto a specified area of the canvas.
OH_Drawing_ErrorCode OH_Drawing_CanvasDrawSingleCharacterWithFeatures(OH_Drawing_Canvas* canvas, const char* str,const OH_Drawing_Font* font, float x, float y, OH_Drawing_FontFeatures* fontFeatures)Draws a single character with font features. If the typeface of the current font does not support the character to draw, the system typeface is used to draw the character.
OH_Drawing_ErrorCode OH_Drawing_CanvasDrawPixelMapMesh(OH_Drawing_Canvas* cCanvas, OH_Drawing_PixelMap* pixelMap, uint32_t meshWidth, uint32_t meshHeight, const float* vertices, uint32_t verticesSize, uint32_t vertOffset, const uint32_t* colors, uint32_t colorsSize, uint32_t colorOffset)Draws a PixelMap based on a mesh, where mesh vertices are evenly distributed across the PixelMap. (This API works with brushes but not pens.)

Enum Description

OH_Drawing_SrcRectConstraint

enum OH_Drawing_SrcRectConstraint

Description

Enumerates the constraint types of the source rectangle.

Since: 12

ValueDescription
STRICT_SRC_RECT_CONSTRAINTThe source rectangle must be completely contained in the image.
FAST_SRC_RECT_CONSTRAINTThe source rectangle can be partly outside the image.

OH_Drawing_PointMode

enum OH_Drawing_PointMode

Description

Enumerates the modes of drawing multiple points. The modes include discrete points, line segments, and open polygons.

Since: 12

ValueDescription
POINT_MODE_POINTSDraws each point separately.
POINT_MODE_LINESDraws every two points as a line segment.
POINT_MODE_POLYGONDraws an array of points as an open polygon.

OH_Drawing_CanvasClipOp

enum OH_Drawing_CanvasClipOp

Description

Enumerates the canvas clipping modes.

Since: 11

ValueDescription
DIFFERENCEClips a specified area. That is, the difference set is obtained.
INTERSECTRetains a specified area. That is, the intersection is obtained.

OH_Drawing_CanvasShadowFlags

enum OH_Drawing_CanvasShadowFlags

Description

Enumerates the shadow flags.

Since: 12

ValueDescription
SHADOW_FLAGS_NONEThere is no shadow flag.
SHADOW_FLAGS_TRANSPARENT_OCCLUDERThe occluding object is transparent.
SHADOW_FLAGS_GEOMETRIC_ONLYNo analysis on the shadows is required.
SHADOW_FLAGS_ALLAll the preceding shadow flags are used.

OH_Drawing_VertexMode

enum OH_Drawing_VertexMode

Description

Enumerates the modes of interpreting the geometry of a given vertex.

Since: 12

ValueDescription
VERTEX_MODE_TRIANGLESDraws a triangle list. Specifically, a list of isolated triangles are drawn using every three vertices. If the number of vertices is not a multiple of 3, the extra vertices will be ignored.
VERTEX_MODE_TRIANGLES_STRIPDraws a triangle strip. Specifically, the first triangle is drawn between the first 3 vertices, and all subsequent triangles use the previous 2 vertices plus the next additional vertex.
VERTEX_MODE_TRIANGLE_FANDraws a triangle fan. A triangle fan is similar to a triangle strip, except that all the triangles share one vertex (the first vertex).

Function Description

OH_Drawing_CanvasDrawSingleCharacterWithFeatures()

OH_Drawing_ErrorCode OH_Drawing_CanvasDrawSingleCharacterWithFeatures(OH_Drawing_Canvas* canvas, const char* str, const OH_Drawing_Font* font, float x, float y, OH_Drawing_FontFeatures* fontFeatures)

Description

Draws a single character with font features. If the typeface of the current font does not support the character to draw, the system typeface is used to draw the character.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
const char* strPointer to the single character to draw. A string can be passed in, but only the first character in the string is parsed and drawn in UTF-8 encoding.
const OH_Drawing_Font* fontPointer to the OH_Drawing_Font object.
float xX coordinate of the left point of the character baseline.
float yY coordinate of the left point of the character baseline.
OH_Drawing_FontFeatures* fontFeaturesPointer to the OH_Drawing_FontFeatures object. If no font feature is set, the preset font feature in the TrueType fonts (TTF) file is used.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if at least one of the parameters canvas, str, font, or fontFeatures is NULL, or the length of str is 0.

OH_Drawing_CanvasDrawPixelMapRectConstraint()

OH_Drawing_ErrorCode OH_Drawing_CanvasDrawPixelMapRectConstraint(OH_Drawing_Canvas* canvas,OH_Drawing_PixelMap* pixelMap, const OH_Drawing_Rect* src, const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions* samplingOptions, OH_Drawing_SrcRectConstraint constraint)

Description

Draws a portion of a pixel map onto a specified area of the canvas.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_PixelMap* pixelMapPointer to the OH_Drawing_PixelMap object.
const OH_Drawing_Rect* srcPointer to a rectangle on the pixel map. If NULL is passed in, it refers to the entire pixel map.
const OH_Drawing_Rect* dstPointer to a rectangle on the canvas.
const OH_Drawing_SamplingOptions* samplingOptionsPointer to the OH_Drawing_SamplingOptions object. A null pointer means that the default sampling options are used.
OH_Drawing_SrcRectConstraint constraintConstraint type. For details about the available options, see OH_Drawing_SrcRectConstraint.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if canvas, pixelMap, or dst is NULL.

OH_Drawing_CanvasDrawRecordCmdNesting()

OH_Drawing_ErrorCode OH_Drawing_CanvasDrawRecordCmdNesting(OH_Drawing_Canvas* canvas, OH_Drawing_RecordCmd* recordCmd)

Description

Draws an OH_Drawing_RecordCmd object. This API supports nesting.

Specifically, it can use the canvas object generated by OH_Drawing_RecordCmdUtilsBeginRecording as the input parameter. However, multi-layer nesting is not recommended because it affects performance.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 19

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object. Only the canvas of the recording type is supported.
OH_Drawing_RecordCmd* recordCmdPointer to the OH_Drawing_RecordCmd object.

Returns

TypeDescription
OH_Drawing_ErrorCodeOperation code.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if either canvas or recordCmd is NULL.

OH_Drawing_CanvasCreate()

OH_Drawing_Canvas* OH_Drawing_CanvasCreate(void)

Description

Creates an OH_Drawing_Canvas object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Returns

TypeDescription
OH_Drawing_Canvas*Returns the pointer to the OH_Drawing_Canvas object created.

OH_Drawing_CanvasCreateWithPixelMap()

OH_Drawing_Canvas* OH_Drawing_CanvasCreateWithPixelMap(OH_Drawing_PixelMap* pixelMap)

Description

Binds a pixel map to a canvas so that the content drawn on the canvas is output to the pixel map. (This process is called CPU rendering.) A canvas bound to a pixel map is a non-recording canvas.
You should unbind the pixel map object by calling OH_Drawing_PixelMapDissolve after the canvas object is destroyed.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_PixelMap* pixelMapPointer to the OH_Drawing_PixelMap object.

Returns

TypeDescription
OH_Drawing_Canvas*Pointer to the created canvas object OH_Drawing_Canvas. If the returned object is NULL, the creation fails due to insufficient memory or an empty pixel map object.

OH_Drawing_CanvasDestroy()

void OH_Drawing_CanvasDestroy(OH_Drawing_Canvas* canvas)

Description

Destroys an OH_Drawing_Canvas object and reclaims the memory occupied by the object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.

OH_Drawing_CanvasBind()

void OH_Drawing_CanvasBind(OH_Drawing_Canvas* canvas, OH_Drawing_Bitmap* bitmap)

Description

Binds a bitmap to a canvas so that the content drawn on the canvas is output to the bitmap. (This process is called CPU rendering.) A canvas bound to a bitmap is a non-recording canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
OH_Drawing_Bitmap* bitmapPointer to an OH_Drawing_Bitmap object.

OH_Drawing_CanvasAttachPen()

void OH_Drawing_CanvasAttachPen(OH_Drawing_Canvas* canvas, const OH_Drawing_Pen* pen)

Description

Attaches a pen to a canvas so that the canvas can use the style and color of the pen to outline a shape. If the pen effect changes after this function is called, you must call the function again to use the new effect in the subsequent drawing.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or pen is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_Pen* penPointer to an OH_Drawing_Pen object.

OH_Drawing_CanvasDetachPen()

void OH_Drawing_CanvasDetachPen(OH_Drawing_Canvas* canvas)

Description

Detaches the pen from a canvas so that the canvas can no longer use the style and color of the pen to outline a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.

OH_Drawing_CanvasAttachBrush()

void OH_Drawing_CanvasAttachBrush(OH_Drawing_Canvas* canvas, const OH_Drawing_Brush* brush)

Description

Attaches a brush to a canvas so that the canvas can use the style and color of the brush to fill in a shape. If the brush effect changes after this function is called, you must call the function again to use the new effect in the subsequent drawing.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_Brush* brushPointer to an OH_Drawing_Brush object.

OH_Drawing_CanvasDetachBrush()

void OH_Drawing_CanvasDetachBrush(OH_Drawing_Canvas* canvas)

Description

Detaches the brush from a canvas so that the canvas can no longer use the previously set brush to fill in a shape.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.

OH_Drawing_CanvasSave()

void OH_Drawing_CanvasSave(OH_Drawing_Canvas* canvas)

Description

Saves the current canvas status (canvas matrix) to the top of the stack. This function works with OH_Drawing_CanvasRestore.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.

OH_Drawing_CanvasSaveLayer()

void OH_Drawing_CanvasSaveLayer(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect, const OH_Drawing_Brush* brush)

Description

Saves the matrix and cropping region, and allocates a bitmap for subsequent drawing. If you call OH_Drawing_CanvasRestore, changes made to the matrix and clipping region are discarded, and the bitmap is drawn.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
const OH_Drawing_Rect* rectPointer to the OH_Drawing_Rect object, which is used to limit the layer size. A null pointer means no limit.
const OH_Drawing_Brush* brushPointer to an OH_Drawing_Brush object. The alpha value, filter effect, and blend mode of the brush are applied when the bitmap is drawn. If NULL is passed in, no effect is applied.

OH_Drawing_CanvasRestore()

void OH_Drawing_CanvasRestore(OH_Drawing_Canvas* canvas)

Description

Restores the canvas status (canvas matrix) saved on the top of the stack.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.

OH_Drawing_CanvasGetSaveCount()

uint32_t OH_Drawing_CanvasGetSaveCount(OH_Drawing_Canvas* canvas)

Description

Obtains the number of canvas statuses (canvas matrices) saved in the stack.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.

Returns

TypeDescription
uint32_tReturns a 32-bit value that describes the number of canvas statuses (canvas matrices). The initial number is 1.

OH_Drawing_CanvasRestoreToCount()

void OH_Drawing_CanvasRestoreToCount(OH_Drawing_Canvas* canvas, uint32_t saveCount)

Description

Restores to a given number of canvas statuses (canvas matrices).
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
uint32_t saveCountNumber of canvas statuses (canvas matrices). If the value is less than or equal to 1, the canvas is restored to the initial state. If the value is greater than the number of canvas statuses that have been saved, no operation is performed.

OH_Drawing_CanvasDrawLine()

void OH_Drawing_CanvasDrawLine(OH_Drawing_Canvas* canvas, float x1, float y1, float x2, float y2)

Description

Draws a line segment.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
float x1X coordinate of the start point of the line segment.
float y1Y coordinate of the start point of the line segment.
float x2X coordinate of the end point of the line segment.
float y2Y coordinate of the end point of the line segment.

OH_Drawing_CanvasDrawPath()

void OH_Drawing_CanvasDrawPath(OH_Drawing_Canvas* canvas, const OH_Drawing_Path* path)

Description

Draws a path.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or path is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_Path* pathPointer to an OH_Drawing_Path object.

OH_Drawing_CanvasDrawPixelMapNine()

OH_Drawing_ErrorCode OH_Drawing_CanvasDrawPixelMapNine(OH_Drawing_Canvas* canvas, OH_Drawing_PixelMap* pixelMap,const OH_Drawing_Rect* center, const OH_Drawing_Rect* dst, OH_Drawing_FilterMode mode)

Description

Splits a pixel map into nine sections using two horizontal and two vertical lines: four edge sections, four corner sections, and a central section.
If the four corner sections are smaller than the target rectangle, they will be drawn in the target rectangle without scaling. Otherwise, they will be scaled to fit the target rectangle.
Any remaining space will be filled by stretching or compressing the other five sections to cover the entire target rectangle.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 18

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_PixelMap* pixelMapPointer to the OH_Drawing_PixelMap object.
const OH_Drawing_Rect* centerPointer to the OH_Drawing_Rect object, which indicates the central rectangle splitting the pixel map. It divides the image into nine sections by extending its four edges.
const OH_Drawing_Rect* dstPointer to the OH_Drawing_Rect object, which indicates the target region on the canvas.
OH_Drawing_FilterMode modeEnumeration of filter modes.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if canvas, pixelMap, or dst is NULL.

OH_Drawing_CanvasDrawPixelMapRect()

void OH_Drawing_CanvasDrawPixelMapRect(OH_Drawing_Canvas* canvas, OH_Drawing_PixelMap* pixelMap,const OH_Drawing_Rect* src, const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions* samplingOptions)

Description

Draws a portion of a pixel map onto a specified area of the canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If one of canvas, pixelMap, or dst is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_PixelMap* pixelMapPointer to the OH_Drawing_PixelMap object.
const OH_Drawing_Rect* srcPointer to a rectangle on the pixel map. If NULL is passed in, it refers to the entire pixel map.
const OH_Drawing_Rect* dstPointer to a rectangle on the canvas.
const OH_Drawing_SamplingOptions* samplingOptionsPointer to the OH_Drawing_SamplingOptions object. A null pointer means that the default sampling options are used.

OH_Drawing_CanvasDrawBackground()

void OH_Drawing_CanvasDrawBackground(OH_Drawing_Canvas* canvas, const OH_Drawing_Brush* brush)

Description

Draws a background filled with a brush.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or brush is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_Brush* brushPointer to an OH_Drawing_Brush object.

OH_Drawing_CanvasDrawRegion()

void OH_Drawing_CanvasDrawRegion(OH_Drawing_Canvas* canvas, const OH_Drawing_Region* region)

Description

Draws a region.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or region is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_Region* regionPointer to an OH_Drawing_Region object.

OH_Drawing_CanvasDrawPoint()

OH_Drawing_ErrorCode OH_Drawing_CanvasDrawPoint(OH_Drawing_Canvas* canvas, const OH_Drawing_Point2D* point)

Description

Draws a point.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
const OH_Drawing_Point2D* pointPointer to the OH_Drawing_Point2D object.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if either canvas or point is NULL.

OH_Drawing_CanvasDrawPoints()

void OH_Drawing_CanvasDrawPoints(OH_Drawing_Canvas* canvas, OH_Drawing_PointMode mode,uint32_t count, const OH_Drawing_Point2D* point2D)

Description

Draws multiple points. You can draw a single point, a line segment, or an open polygon.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or point2D is NULL, or count is 0, OH_DRAWING_ERROR_INVALID_PARAMETER is returned. If mode is not within the enumerated range, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
OH_Drawing_PointMode modeMode for drawing multiple points. For details, see OH_Drawing_PointMode.
uint32_t countNumber of vertices, that is, the number of vertices in the vertex array.
const OH_Drawing_Point2D* point2DPointer to an array holding the vertices.

OH_Drawing_CanvasDrawBitmap()

void OH_Drawing_CanvasDrawBitmap(OH_Drawing_Canvas* canvas, const OH_Drawing_Bitmap* bitmap, float left, float top)

Description

Draws a bitmap. A bitmap, also referred to as a dot matrix image, a pixel map image, or a grid image, includes single points called pixels (image elements).
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_Bitmap* bitmapPointer to an OH_Drawing_Bitmap object.
float leftX coordinate of the upper left corner of the bitmap.
float topY coordinate of the upper left corner of the bitmap.

OH_Drawing_CanvasDrawBitmapRect()

void OH_Drawing_CanvasDrawBitmapRect(OH_Drawing_Canvas* canvas, const OH_Drawing_Bitmap* bitmap,const OH_Drawing_Rect* src, const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions* samplingOptions)

Description

Draws a portion of a bitmap onto a specified area of the canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If one of canvas, bitmap, or dst is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
const OH_Drawing_Bitmap* bitmapPointer to the OH_Drawing_Bitmap object.
const OH_Drawing_Rect* srcPointer to a rectangle on the bitmap. If NULL is passed in, it refers to the entire bitmap.
const OH_Drawing_Rect* dstPointer to a rectangle on the canvas.
const OH_Drawing_SamplingOptions* samplingOptionsPointer to the OH_Drawing_SamplingOptions object. A null pointer means that the default sampling options are used.

OH_Drawing_CanvasDrawRect()

void OH_Drawing_CanvasDrawRect(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect)

Description

Draws a rectangle.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or OH_Drawing_Rect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_Rect* rectPointer to an OH_Drawing_Rect object.

OH_Drawing_CanvasDrawCircle()

void OH_Drawing_CanvasDrawCircle(OH_Drawing_Canvas* canvas, const OH_Drawing_Point* point, float radius)

Description

Draws a circle. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If either canvas or point is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If radius is less than or equal to 0, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_Point* pointPointer to an OH_Drawing_Point object, which indicates the center of the circle.
float radiusRadius of the circle. The value is invalid if it is less than or equal to 0.

OH_Drawing_CanvasDrawColor()

OH_Drawing_ErrorCode OH_Drawing_CanvasDrawColor(OH_Drawing_Canvas* canvas, uint32_t color,OH_Drawing_BlendMode blendMode)

Description

Fills the entire canvas with the specified color and blend mode.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
uint32_t colorColor, represented by a 32-bit (ARGB) variable.
OH_Drawing_BlendMode blendModeBlend mode.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if canvas is NULL.
OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE if blendMode is not set to one of the enumerated values.

OH_Drawing_CanvasDrawOval()

void OH_Drawing_CanvasDrawOval(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect)

Description

Draws an oval. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If either canvas or rect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_Rect* rectPointer to an OH_Drawing_Rect object.

OH_Drawing_CanvasDrawArc()

void OH_Drawing_CanvasDrawArc(OH_Drawing_Canvas* canvas,const OH_Drawing_Rect* rect, float startAngle, float sweepAngle)

Description

Draws an arc. If the absolute value of the sweep angle exceeds 360 degrees, an ellipse is drawn.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or rect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_Rect* rectPointer to an OH_Drawing_Rect object.
float startAngleStart angle. When the degree is 0, the start point is located at the right end of the oval. A positive number indicates that the start point is placed clockwise, and a negative number indicates that the start point is placed counterclockwise.
float sweepAngleAngle to sweep, in degrees. A positive number indicates a clockwise sweep, and a negative value indicates a counterclockwise swipe. The valid range is from -360 degrees to 360 degrees. If the absolute value of the sweep angle exceeds 360 degrees, an ellipse is drawn.

OH_Drawing_CanvasDrawArcWithCenter()

OH_Drawing_ErrorCode OH_Drawing_CanvasDrawArcWithCenter(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect,float startAngle, float sweepAngle, bool useCenter)

Description

Draws an arc. It enables you to define the start angle, sweep angle, and whether the arc's endpoints should connect to its center.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 18

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
const OH_Drawing_Rect* rectPointer to the OH_Drawing_Rect object.
float startAngleStart angle, in degrees. The value is a floating point number. When the degree is 0, the start point is located at the right end of the oval. A positive number indicates that the start point is placed clockwise, and a negative number indicates that the start point is placed counterclockwise.
float sweepAngleAngle to sweep, in degrees. The value is a floating point number. A positive number indicates a clockwise sweep, and a negative value indicates a counterclockwise swipe. The swipe angle can exceed 360 degrees, and a complete ellipse is drawn.
bool useCenterWhether the start point and end point of the arc are connected to its center. The value true means that they are connected to the center; the value false means the opposite.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if either canvas or rect is NULL.

OH_Drawing_CanvasDrawRoundRect()

void OH_Drawing_CanvasDrawRoundRect(OH_Drawing_Canvas* canvas, const OH_Drawing_RoundRect* roundRect)

Description

Draws a rounded rectangle. This API may return an error code. For details, call OH_Drawing_ErrorCodeGet. If either canvas or roundRect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_RoundRect* roundRectPointer to an OH_Drawing_RoundRect object.

OH_Drawing_CanvasDrawNestedRoundRect()

OH_Drawing_ErrorCode OH_Drawing_CanvasDrawNestedRoundRect(OH_Drawing_Canvas* canvas, const OH_Drawing_RoundRect* outer,const OH_Drawing_RoundRect* inner)

Description

Draws two nested rounded rectangles. The outer rectangle boundary must contain the inner rectangle boundary. Otherwise, there is no drawing effect.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 18

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
const OH_Drawing_RoundRect* outerPointer to the OH_Drawing_RoundRect object, indicating the outer rounded rectangle.
const OH_Drawing_RoundRect* innerPointer to the OH_Drawing_RoundRect object, indicating the inner rounded rectangle.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if canvas, outer, or inner is NULL.

OH_Drawing_CanvasDrawSingleCharacter()

OH_Drawing_ErrorCode OH_Drawing_CanvasDrawSingleCharacter(OH_Drawing_Canvas* canvas, const char* str,const OH_Drawing_Font* font, float x, float y)

Description

Draws a single character. If the typeface of the current font does not support the character to draw, the system typeface is used to draw the character.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
const char* strPointer to the single character to draw. A string can be passed in, but only the first character in the string is parsed and drawn in UTF-8 encoding.
const OH_Drawing_Font* fontPointer to the OH_Drawing_Font object.
float xX coordinate of the left point of the character baseline.
float yY coordinate of the left point of the character baseline.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if at least one of the parameters canvas, str, or font is NULL, or the length of str is 0.

OH_Drawing_CanvasDrawTextBlob()

void OH_Drawing_CanvasDrawTextBlob(OH_Drawing_Canvas* canvas, const OH_Drawing_TextBlob* textBlob, float x, float y)

Description

Draws a text blob. If the typeface used to construct OH_Drawing_TextBlob does not support a character, that character will not be drawn.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or textBlob is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_TextBlob* textBlobPointer to an OH_Drawing_TextBlob object.
float xX coordinate of the left point of the text baseline.
float yY coordinate of the left point of the text baseline.

OH_Drawing_CanvasClipRect()

void OH_Drawing_CanvasClipRect(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect,OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias)

Description

Clips a rectangle.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or rect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If clipOp is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_Rect* rectPointer to an OH_Drawing_Rect object.
OH_Drawing_CanvasClipOp clipOpClip mode. For details about the available options, see OH_Drawing_CanvasClipOp.
bool doAntiAliasWhether to enable anti-aliasing. The value true means to enable anti-aliasing, and false means the opposite.

OH_Drawing_CanvasClipRoundRect()

void OH_Drawing_CanvasClipRoundRect(OH_Drawing_Canvas* canvas, const OH_Drawing_RoundRect* roundRect,OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias)

Description

Clips a rounded rectangle.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or roundRect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If clipOp is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_RoundRect* roundRectPointer to an OH_Drawing_RoundRect object.
OH_Drawing_CanvasClipOp clipOpClip mode. For details about the available options, see OH_Drawing_CanvasClipOp.
bool doAntiAliasWhether to perform anti-aliasing. The value true means to perform anti-aliasing, and false means the opposite.

OH_Drawing_CanvasClipPath()

void OH_Drawing_CanvasClipPath(OH_Drawing_Canvas* canvas, const OH_Drawing_Path* path,OH_Drawing_CanvasClipOp clipOp, bool doAntiAlias)

Description

Clips a path.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or path is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If clipOp is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
const OH_Drawing_Path* pathPointer to an OH_Drawing_Path object.
OH_Drawing_CanvasClipOp clipOpClip mode. For details about the available options, see OH_Drawing_CanvasClipOp.
bool doAntiAliasWhether to enable anti-aliasing. The value true means to enable anti-aliasing, and false means the opposite.

OH_Drawing_CanvasClipRegion()

OH_Drawing_ErrorCode OH_Drawing_CanvasClipRegion(OH_Drawing_Canvas* canvas, const OH_Drawing_Region* region,OH_Drawing_CanvasClipOp clipOp)

Description

Clips a rectangle.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
const OH_Drawing_Region* regionPointer to the OH_Drawing_Region object.
OH_Drawing_CanvasClipOp clipOpClip mode. For details about the available options, see OH_Drawing_CanvasClipOp.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if either canvas or region is NULL.
OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE if clipOp is not set to one of the enumerated values.

OH_Drawing_CanvasRotate()

void OH_Drawing_CanvasRotate(OH_Drawing_Canvas* canvas, float degrees, float px, float py)

Description

Rotates a canvas by a given angle. A positive value indicates a clockwise rotation, and a negative value indicates a counterclockwise rotation.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
float degreesRotation angle.
float pxX coordinate of the rotation point.
float pyY coordinate of the rotation point.

OH_Drawing_CanvasTranslate()

void OH_Drawing_CanvasTranslate(OH_Drawing_Canvas* canvas, float dx, float dy)

Description

Translates a canvas by a given distance.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
float dxDistance to translate on the X axis.
float dyDistance to translate on the Y axis.

OH_Drawing_CanvasScale()

void OH_Drawing_CanvasScale(OH_Drawing_Canvas* canvas, float sx, float sy)

Description

Scales a canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
float sxScale ratio on the X axis.
float syScale ratio on the Y axis.

OH_Drawing_CanvasSkew()

void OH_Drawing_CanvasSkew(OH_Drawing_Canvas* canvas, float sx, float sy)

Description

Skews a canvas. This function premultiplies the current canvas matrix by a skew transformation matrix and applies the resulting matrix to the canvas. The skew transformation matrix is as follows:
|1 sx 0|
|sy 1 0|
|0 0 1|
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
float sxAmount of tilt on the X axis. A positive number tilts the drawing rightwards along the positive direction of the Y axis, and a negative number tilts the drawing leftwards along the positive direction of the Y axis.
float syAmount of tilt on the Y axis. A positive number tilts the drawing downwards along the positive direction of the X axis, and a negative number tilts the drawing upwards along the positive direction of the X axis.

OH_Drawing_CanvasGetWidth()

int32_t OH_Drawing_CanvasGetWidth(OH_Drawing_Canvas* canvas)

Description

Obtains the canvas width.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.

Returns

TypeDescription
int32_tReturns the canvas width, in px.

OH_Drawing_CanvasGetHeight()

int32_t OH_Drawing_CanvasGetHeight(OH_Drawing_Canvas* canvas)

Description

Obtains the canvas height.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.

Returns

TypeDescription
int32_tReturns the canvas height, in pixels.

OH_Drawing_CanvasGetLocalClipBounds()

void OH_Drawing_CanvasGetLocalClipBounds(OH_Drawing_Canvas* canvas, OH_Drawing_Rect* rect)

Description

Obtains the bounds of the cropping region of the canvas. This function cannot be used for a canvas of the recording type.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or rect is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_Rect* rectPointer to the OH_Drawing_Rect object. You can call OH_Drawing_RectCreate to create a rectangle object.

OH_Drawing_CanvasGetTotalMatrix()

void OH_Drawing_CanvasGetTotalMatrix(OH_Drawing_Canvas* canvas, OH_Drawing_Matrix* matrix)

Description

Obtains the 3x3 matrix of a canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or matrix is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_Matrix* matrixPointer to the OH_Drawing_Matrix object. You can call OH_Drawing_MatrixCreate to create a matrix object.

OH_Drawing_CanvasConcatMatrix()

void OH_Drawing_CanvasConcatMatrix(OH_Drawing_Canvas* canvas, OH_Drawing_Matrix* matrix)

Description

Preconcats the existing matrix of the canvas with the passed-in matrix. The drawing operation triggered before this API is called is not affected.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or matrix is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_Matrix* matrixPointer to the OH_Drawing_Matrix object.

OH_Drawing_CanvasDrawShadow()

void OH_Drawing_CanvasDrawShadow(OH_Drawing_Canvas* canvas, OH_Drawing_Path* path, OH_Drawing_Point3D planeParams,OH_Drawing_Point3D devLightPos, float lightRadius, uint32_t ambientColor, uint32_t spotColor,OH_Drawing_CanvasShadowFlags flag)

Description

Draws a spot shadow and uses a given path to outline the ambient shadow.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or path is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If flag is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_Path* pathPointer to the OH_Drawing_Path object, which is used to generate shadows.
OH_Drawing_Point3D planeParamsZ-axis offset of an occluder relative to the canvas, based on its x and y coordinates.
OH_Drawing_Point3D devLightPosPosition of the light relative to the canvas.
float lightRadiusRadius of the light source. The value must be greater than or equal to 0.
uint32_t ambientColorAmbient shadow color, which is represented by a 32-bit (ARGB) variable.
uint32_t spotColorPoint shadow color, which is represented by a 32-bit (ARGB) variable.
OH_Drawing_CanvasShadowFlags flagEnumeration of shadow flags.

OH_Drawing_CanvasClear()

void OH_Drawing_CanvasClear(OH_Drawing_Canvas* canvas, uint32_t color)

Description

Clears a canvas by using a given color.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
uint32_t colorColor, which is a 32-bit (ARGB) variable.

OH_Drawing_CanvasSetMatrix()

void OH_Drawing_CanvasSetMatrix(OH_Drawing_Canvas* canvas, OH_Drawing_Matrix* matrix)

Description

Sets the matrix status for a canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or matrix is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_Matrix* matrixPointer to the OH_Drawing_Matrix object. You can call OH_Drawing_MatrixCreate to create a matrix object.

OH_Drawing_CanvasResetMatrix()

void OH_Drawing_CanvasResetMatrix(OH_Drawing_Canvas* canvas)

Description

Resets the matrix of this canvas to an identity matrix.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If canvas is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.

OH_Drawing_CanvasDrawImageRectWithSrc()

void OH_Drawing_CanvasDrawImageRectWithSrc(OH_Drawing_Canvas* canvas, const OH_Drawing_Image* image,const OH_Drawing_Rect* src, const OH_Drawing_Rect* dst, const OH_Drawing_SamplingOptions* samplingOptions,OH_Drawing_SrcRectConstraint srcRectConstraint)

Description

Draws a portion of an image onto a specified area of the canvas. The area selected by the source rectangle is scaled and translated to the destination rectangle.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If one of canvas, image, src, or dst is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
const OH_Drawing_Image* imagePointer to the OH_Drawing_Image object.
const OH_Drawing_Rect* srcPointer to the OH_Drawing_Rect object.
const OH_Drawing_Rect* dstPointer to the OH_Drawing_Rect object.
const OH_Drawing_SamplingOptions* samplingOptionsPointer to the OH_Drawing_SamplingOptions object. A null pointer means that the default sampling options are used.
OH_Drawing_SrcRectConstraint srcRectConstraintConstraint type. For details about the available options, see OH_Drawing_SrcRectConstraint.

OH_Drawing_CanvasDrawImageRect()

void OH_Drawing_CanvasDrawImageRect(OH_Drawing_Canvas* canvas, OH_Drawing_Image* image,OH_Drawing_Rect* rect, OH_Drawing_SamplingOptions* samplingOptions)

Description

Draws an image onto a specified area of the canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If one of canvas, image, or dst is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_Image* imagePointer to the OH_Drawing_Image object.
OH_Drawing_Rect* rectPointer to the OH_Drawing_Rect object.
OH_Drawing_SamplingOptions* samplingOptionsPointer to the OH_Drawing_SamplingOptions object. A null pointer means that the default sampling options are used.

OH_Drawing_CanvasDrawVertices()

void OH_Drawing_CanvasDrawVertices(OH_Drawing_Canvas* canvas, OH_Drawing_VertexMode vertexMmode,int32_t vertexCount, const OH_Drawing_Point2D* positions, const OH_Drawing_Point2D* texs,const uint32_t* colors, int32_t indexCount, const uint16_t* indices, OH_Drawing_BlendMode mode)

Description

Draws a triangular grid described by a vertex array.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or positions is NULL, vertexCount is less than 3, or indexCount is less than 3 but not 0, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
If either vertexMmode or mode is not set to one of the enumerated values, OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to an OH_Drawing_Canvas object.
OH_Drawing_VertexMode vertexMmodeMode for drawing vertices. For details about the available options, see OH_Drawing_VertexMode.
int32_t vertexCountNumber of elements in the vertex array. The value must be greater than or equal to 3.
const OH_Drawing_Point2D* positionsPointer to the array that holds the position of every vertex. The array cannot be null and its length must be equal to the value of vertexCount.
const OH_Drawing_Point2D* texsPointer to the array that holds the texture space coordinate corresponding to each vertex. The array can be null. If the array is not null, its length must be equal to the value of vertexCount.
const uint32_t* colorsPointer to the array that holds the color corresponding to each vertex. It is used for interpolation in a triangle. The array can be null. If the array is not null, its length must be equal to the value of vertexCount.
int32_t indexCountNumber of indices. The value can be 0 or a value greater than or equal to 3.
const uint16_t* indicesPointer to the array that holds the index of each vertex. The array can be null. If the array is not null, its length must be equal to the value of indexCount.
OH_Drawing_BlendMode modeEnumeration of blend modes. For details about the available options, see OH_Drawing_BlendMode.

OH_Drawing_CanvasReadPixels()

bool OH_Drawing_CanvasReadPixels(OH_Drawing_Canvas* canvas, OH_Drawing_Image_Info* imageInfo,void* dstPixels, uint32_t dstRowBytes, int32_t srcX, int32_t srcY)

Description

Copies pixel data from a canvas to a specified address. This function cannot be used for a canvas of the recording type.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If one of canvas, imageInfo, or dstPixels is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_Image_Info* imageInfoPointer to the OH_Drawing_Image_Info object.
void* dstPixelsPointer to the start address for storing the pixel data.
uint32_t dstRowBytesNumber of bytes in each row of pixels. The value is invalid if it is less than or equal to 0.
int32_t srcXX offset of the pixels on the canvas, in px.
int32_t srcYY offset of the pixels on the canvas, in px.

Returns

TypeDescription
boolReturns true if the pixel data is copied to the start address of the storage; returns false otherwise.

OH_Drawing_CanvasReadPixelsToBitmap()

bool OH_Drawing_CanvasReadPixelsToBitmap(OH_Drawing_Canvas* canvas,OH_Drawing_Bitmap* bitmap, int32_t srcX, int32_t srcY)

Description

Copies pixel data from a canvas to an image. This function cannot be used for a canvas of the recording type.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If either canvas or bitmap is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_Bitmap* bitmapPointer to the OH_Drawing_Bitmap object.
int32_t srcXX offset of the pixels on the canvas, in px.
int32_t srcYY offset of the pixels on the canvas, in px.

Returns

TypeDescription
boolReturns true if the pixel data is copied to the image; returns false otherwise.

OH_Drawing_CanvasIsClipEmpty()

OH_Drawing_ErrorCode OH_Drawing_CanvasIsClipEmpty(OH_Drawing_Canvas* canvas, bool* isClipEmpty)

Description

Checks whether the region that can be drawn is empty after clipping.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
bool* isClipEmptyPointer to the variable that specifies whether the region is empty. The value true means that the region is empty, and false means the opposite.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if either canvas or isClipEmpty is NULL.

OH_Drawing_CanvasGetImageInfo()

OH_Drawing_ErrorCode OH_Drawing_CanvasGetImageInfo(OH_Drawing_Canvas* canvas, OH_Drawing_Image_Info* imageInfo)

Description

Obtains the image information of a canvas.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_Image_Info* imageInfoPointer to the OH_Drawing_Image_Info object.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if either canvas or imageInfo is NULL.

OH_Drawing_CanvasDrawRecordCmd()

OH_Drawing_ErrorCode OH_Drawing_CanvasDrawRecordCmd(OH_Drawing_Canvas* canvas, OH_Drawing_RecordCmd* recordCmd)

Description

Draws an OH_Drawing_RecordCmd object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 13

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object. Only the canvas of the recording type is supported.
OH_Drawing_RecordCmd* recordCmdPointer to the OH_Drawing_RecordCmd object.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if either canvas or recordCmd is NULL.

OH_Drawing_CanvasQuickRejectPath()

OH_Drawing_ErrorCode OH_Drawing_CanvasQuickRejectPath(OH_Drawing_Canvas* canvas, const OH_Drawing_Path* path,bool* quickReject)

Description

Checks whether the path is not intersecting with the canvas area. The canvas area includes its boundaries.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 18

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
const OH_Drawing_Path* pathPointer to the OH_Drawing_Path object.
bool* quickRejectPointer to the check result. The value true means that the path is not intersecting with the canvas area, and false means the opposite.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if canvas, path, or quickReject is NULL.

OH_Drawing_CanvasQuickRejectRect()

OH_Drawing_ErrorCode OH_Drawing_CanvasQuickRejectRect(OH_Drawing_Canvas* canvas, const OH_Drawing_Rect* rect,bool* quickReject)

Description

Checks whether the rectangle is not intersecting with the canvas area. The canvas area includes its boundaries.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 18

Parameters

NameDescription
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object.
const OH_Drawing_Rect* rectPointer to the OH_Drawing_Rect object.
bool* quickRejectPointer to the check result. The value true means that the rectangle is not intersecting with the canvas area, and false means the opposite.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if canvas, rect, or quickReject is NULL.

OH_Drawing_CanvasDrawPixelMapMesh()

OH_Drawing_ErrorCode OH_Drawing_CanvasDrawPixelMapMesh(OH_Drawing_Canvas* cCanvas, OH_Drawing_PixelMap* pixelMap, uint32_t meshWidth, uint32_t meshHeight, const float* vertices, uint32_t verticesSize, uint32_t vertOffset, const uint32_t* colors, uint32_t colorsSize, uint32_t colorOffset)

Description

Draws a PixelMap based on a mesh, where mesh vertices are evenly distributed across the PixelMap. (This API works with brushes but not pens.)

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 23

Parameters

NameDescription
OH_Drawing_Canvas* cCanvasPointer to the OH_Drawing_Canvas object.
OH_Drawing_PixelMap* pixelMapPointer to the OH_Drawing_PixelMap object.
uint32_t meshWidthNumber of columns in the mesh. The value is an integer greater than 0.
uint32_t meshHeightNumber of rows in the mesh. The value is an integer greater than 0.
const float* verticesPointer to the mesh vertex array.
uint32_t verticesSizeSize of the mesh vertex array. The value must be ((meshWidth + 1) * (meshHeight + 1) + vertoffset) * 2.
uint32_t vertOffsetNumber of vertices to skip before drawing. The value is an integer greater than or equal to 0.
const uint32_t* colorsPointer to the mesh color array, which can be null.
uint32_t colorsSizeSize of the mesh color array. If the array exists, the size must be (meshWidth + 1) * (meshHeight + 1) + colorOffset.
uint32_t colorOffsetNumber of colors to skip before drawing. The value is an integer greater than or equal to 0.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if any of the parameters, such as cCanvas, pixelMap, and vertices, is empty or the input parameter does not meet the value rule.

你可能感兴趣的鸿蒙文章

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/rWSfyOiK