# CanvasGetPixels

int CanvasGetPixels (int panelHandle, int controlID, Rect rect, int pixelColors[]);

## Purpose

Obtains the colors of the pixels in a specific rectangular area of a canvas control.

| Note The canvas control maintains an internal bitmap reflecting all of the drawing operations (except for drawing operations made while the ATTR_DRAW_POLICY attribute is VAL_DIRECT_TO_SCREEN). Sometimes the internal bitmap contains the result of recent drawing operations that have not yet been reflected on the screen. CanvasGetPixels obtains the pixel colors from the internal bitmap, not from the screen.

## Parameters

Input
Name | Type | Description
panelHandle | integer | Specifier for a particular panel that is currently in memory. You obtain this handle from LoadPanel, NewPanel, or DuplicatePanel.
controlID | integer | The defined constant, located in the .uir header file, that you assigned to the control in the User Interface Editor, or the ID returned by NewCtrl or DuplicateCtrl.
rect | Rect | Rect structure that specifies the location and size of the rectangular area from which to obtain the pixel colors. Location and size are expressed in terms of unscaled pixel coordinates. The origin (0,0) is the upper left corner of the canvas control. Use VAL_ENTIRE_OBJECT to specify the entire canvas. The Rect structure is defined as follows: typedef struct { int top; int left; int height; int width; } Rect; You can create a Rect without having to declare a variable by using the following function: Rect MakeRect (int top, int left, int height, int width); Example CanvasGetPixels (panelHandle, controlID, VAL_ENTIRE_OBJECT, pixelArray);
Output
Name | Type | Description
pixelColors | integer array | Array of RGB color values of the pixels in the specified rectangle. The total number of elements in the pixelColors array must be equal to rect.height * rect.width. The pixel color values are stored in row-major order. For example, consider a rect with the following values: rect.top = 50 rect.left = 60 rect.height = 20 rect.width = 15 The color of pixel {x = 65, y = 58} of this rect is stored in a pixel array at the following index: pixelArray[(y — rect.top) × rect.width + (x — rect.left)] pixelArray[(58 — 50) × 15 + (65 — 60)] When using a rect.width of VAL_TO_EDGE, substitute the following for rect.width in the preceding formula: (total width of canvas) — rect.left

## Return Value

Name | Type | Description
status | integer | Return value indicating whether the function was successful. A negative number indicates that an error occurred.
Code | Error Message String
xx | Success