Admin Production ni-theme
Current Publication

CanvasDrawBitmap

LabWindows/CVI

CanvasDrawBitmap

int CanvasDrawBitmap (int panelHandle, int controlID, int bitmapID, Rect sourceRectangle, Rect destinationRectangle);

Purpose

Draws a bitmap image, or portion thereof, in the destination rectangle that you specify on a canvas control.

Note   Canvas controls do not support partial transparency; each pixel is either opaque or fully transparent. If you use this function to draw a bitmap containing an alpha channel over some region of a transparent canvas, that region will no longer be transparent. If you need to overlay a bitmap with an alpha channel on top of a transparent canvas, create a transparent picture control, associate the bitmap with the picture control, and then place the picture control over the canvas.

Example Code

The following code copies a bitmap image, without any stretching or shrinking, to the canvas control, starting 20 pixels below the top edge of the canvas, and 30 pixels to the right of left edge of the canvas:

CanvasDrawBitmap (panelHandle, controlID, bitmapID, VAL_ENTIRE_OBJECT, MakeRect(20,30, VAL_KEEP_SAME_SIZE, VAL_KEEP_SAME_SIZE));

Supported Controls

You can use CanvasDrawBitmap 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.
bitmapID int ID of the bitmap object that contains the image. You can obtain the ID from functions such as NewBitmapEx and GetCtrlBitmap.
sourceRectangle Rect Rect structure specifying the portion of the bitmap to draw. The values are in terms of the pixel coordinates of the bitmap. The origin (0,0) is at the upper left corner of the bitmap.

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);

Use VAL_ENTIRE_OBJECT to specify the entire image.

Example

CanvasDrawBitmap (panelHandle, controlID, bitmapID, VAL_ENTIRE_OBJECT, destinationRect);

destinationRectangle Rect Rect structure specifying the size and location of the area in which to draw the bitmap image on the canvas control. If sourceRect and destinationRect are not the same size, the bitmap stretches or shrinks to fit.

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);

Use VAL_ENTIRE_OBJECT to specify the entire image.

If you want the bitmap to stretch to fit the size of the canvas, pass VAL_ENTIRE_OBJECT as destinationRect.

Example

CanvasDrawBitmap (panelHandle, controlID, bitmapID, sourceRectangle, MakeRect(20,30, VAL_KEEP_SAME_SIZE, VAL_KEEP_SAME_SIZE));

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

Examples

Refer to the following examples that use the CanvasDrawBitmap function:

  • toolbox\msgdemo.cws

    Open example
  • userint\alphablend.cws

    Open example
  • userint\canvas.cws

    Open example
  • userint\clipbord.cws

    Open example