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. |
Supported Controls
You can use CanvasGetPixels with canvas controls.
Parameters
Input | ||
Name | Type | Description |
panelHandle | int | Specifier for a particular panel that is currently in memory. You can obtain this handle from functions such as LoadPanel and NewPanel. |
controlID | int | 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 functions such as NewCtrl and 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); ExampleCanvasGetPixels (panelHandle, controlID, VAL_ENTIRE_OBJECT, pixelArray); |
Output | ||
Name | Type | Description |
pixelColors | int [] | 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 | int | Return value indicating whether the function was successful. A negative number indicates that an error occurred. |
Additional Information
Library: User Interface Library
Include file: userint.h
LabWindows/CVI compatibility: LabWindows/CVI 4.0 and later
Example
Refer to apps\iconedit\iconedit.cws for an example of using the CanvasGetPixels function.