L_SetBitmapRgnHandle

#include "l_bitmap.h"

L_INT EXT_FUNCTION L_SetBitmapRgnHandle(pBitmap, pXForm, hRgn, uCombineMode)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

pRGNXFORM pXForm;

/* pointer to a coordinate-translation structure */

HRGN hRgn;

/* handle to the Windows region */

L_UINT uCombineMode;

/* action to take regarding the existing region */

Creates or updates the bitmap region by adding a region that is specified by a Windows region handle.

Parameter

Description

pBitmap

Pointer to the bitmap handle referencing the bitmap where the region is to be created or updated.

pXForm

Pointer to an RGNXFORM structure that LEADTOOLS uses to translate between display coordinates and bitmap coordinates.

 

You should create this structure when the Windows region is created. Otherwise the device context values may not be available when you are ready to add the Windows region to the bitmap region.

 

If you specify NULL in this parameter, the scalar fields default to 1, the offsets default to 0, and the view perspective defaults to the bitmap's view perspective.

hRgn

Handle to the Windows region.

uCombineMode

The action to take regarding the existing bitmap region, if one is defined. For descriptions of the possible values, refer to Creating a Bitmap Region.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Before calling this function, you must declare an RGNXFORM structure and set its values, which LEADTOOLS uses to translate between device context coordinates and bitmap coordinates. For details about how the structure works refer to the RGNXFORM structure description. For a description of common usage, refer to Translating Coordinates for a Bitmap Region.

The device coordinates are the ones that were in effect at the time the Windows region was created.

If you want to assign a region from one bitmap to another, you must use the L_GetBitmapRgnHandle function to get region from the first bitmap; then use the L_SetBitmapRgnHandle function to assign the region to the second bitmap.

To update an existing region, you specify how the new region is to be combined with the existing one. For descriptions of the possibilities, refer to Creating a Bitmap Region.

Required DLLs and Libraries

LTDIS

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 95 / 98 / Me, Windows 2000 / XP.

See Also

Functions:

L_GetBitmapRgnHandle

Topics:

Raster Image Functions: Creating and Using a Region

 

Raster Image Functions: Region Processing

 

Defining and Using a Bitmap Region

 

Saving a Region

Example

For complete sample code, refer to the DRAW example.

/* This example creates and saves one elliptical region. It then creates a second 
elliptical region and adds the saved region to it. Finally, it lightens the part of 
the bitmap that is in the resulting region. */
BITMAPHANDLE LeadBitmap;   /* Bitmap handle for the image */
void TestFunction(HWND hWnd)
{
   RGNXFORM XFormToBitmap; /* Structure for transforming display coordinates */
   RGNXFORM XFormFromBitmap; /* Structure for transforming bitmap coordinates */
   HDC hWindowDC;  /* Device context of the current window */
   RECT rClientArea; /* Client area of the current window */
   RECT rRgnRect; /* Rectangle that defines the region */
   HRGN SavedRegion; /* Windows region handle used to save a region */
   /* Get the device context of the current window */
   hWindowDC = GetDC (hWnd);
   /* Get the client area of the current window */
   GetClientRect(hWnd,&rClientArea);
   /* Load a bitmap */
   L_LoadBitmap (TEXT("IMAGE3.CMP"), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
   /* Set XFormToBitmap fields, assuming that the display rectangle is the same
   as the client area of the current window */
   XFormToBitmap.uViewPerspective = TOP_LEFT;
   XFormToBitmap.nXScalarNum = BITMAPWIDTH(&LeadBitmap);
   XFormToBitmap.nXScalarDen = rClientArea.right;
   XFormToBitmap.nYScalarNum = BITMAPHEIGHT(&LeadBitmap);
   XFormToBitmap.nYScalarDen = rClientArea.bottom;
   XFormToBitmap.nXOffset = 0;
   XFormToBitmap.nYOffset = 0;
   /* Set XFormFromBitmap fields, assuming that the display rectangle is the same
   as the client area of the current window */
   XFormFromBitmap.uViewPerspective = TOP_LEFT;
   XFormFromBitmap.nXScalarNum = rClientArea.right;
   XFormFromBitmap.nXScalarDen = BITMAPWIDTH(&LeadBitmap);
   XFormFromBitmap.nYScalarNum = rClientArea.bottom;
   XFormFromBitmap.nYScalarDen = BITMAPHEIGHT(&LeadBitmap);
   XFormFromBitmap.nXOffset = 0;
   XFormFromBitmap.nYOffset = 0;
   /* Specify a rectangle to define the first elliptical region */
   SetRect(&rRgnRect, 0, rClientArea.bottom/8, 
      rClientArea.right/4, rClientArea.bottom/2);
   /* Create the first elliptical region */
   L_SetBitmapRgnEllipse(&LeadBitmap, &XFormToBitmap, &rRgnRect, L_RGN_SET);
   /* Save the first elliptical region */
   L_GetBitmapRgnHandle(&LeadBitmap, &XFormFromBitmap, &SavedRegion);
   /* Free the region */
   L_FreeBitmapRgn(&LeadBitmap);
   /* Specify a rectangle to define the second elliptical region */
   SetRect(&rRgnRect, rClientArea.right/4, rClientArea.bottom/8, 
      rClientArea.right/2, rClientArea.bottom/2);
   /* Create the second elliptical region */
   L_SetBitmapRgnEllipse(&LeadBitmap, &XFormToBitmap, &rRgnRect, L_RGN_SET);
   /* Add the saved region to the new one, resulting in side-by-side elliptical shapes */
   L_SetBitmapRgnHandle(&LeadBitmap, &XFormToBitmap, SavedRegion, L_RGN_OR);
   /* Lighten the region so that we will see it */
   L_ChangeBitmapIntensity(&LeadBitmap,500);
   /* Delete the HRGN object */
   DeleteObject(SavedRegion);
   return;
}