L_SetBitmapRgnMagicWand

#include "l_bitmap.h"

L_LTDIS_API L_INT L_SetBitmapRgnMagicWand(pBitmap, x, y, crLowerTolerance, crUpperTolerance, uCombineMode)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

L_INT x;

/* x coordinate */

L_INT y;

/* y coordinate */

L_COLORREF crLowerTolerance;

/* upper tolerance values */

L_COLORREF crUpperTolerance;

/* upper tolerance values */

L_UINT uCombineMode;

/* action to take regarding the existing region */

Sets a region based on the color found at point x, y in the bitmap.

Parameter

Description

pBitmap

Pointer to the bitmap handle referencing the bitmap.

x

X coordinate of a point. The color of the specified point will be used to set the region.

y

Y coordinate of a point. The color of the specified point will be used to set the region.

crLowerTolerance

Lower tolerance values that set the lower stopping point for the region.

crUpperTolerance

Upper tolerance values that set the upper stopping point for the 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

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.

For gray scale bitmaps:

The minimum channel tolerance value of crLowerTolerance will be used to set the lower stopping point, and the value of crUpperTolerance will be used to set the upper stopping point. For example, if the value of the pixel at (x, y) is (125, 125, 125) and crLowerTolerance is (20,30,15), the smallest value of the triplet (15) will be used to create the lower stopping point of (110,110,110). If crUpperTolerance is (10,25,20), the smallest value of that triplet (10) will be used to create the upper stopping point of (135,135,135).

This function supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available in Document and Medical Imaging toolkits.

The standard Windows values for COLORREF represent either red, green, and blue color values, or an index into the bitmap's palette. A COLORREF value with the format 0x00BBGGRR represents the blue, green, and red color values for the specified pixel, where 0xBB is the blue value, 0xGG is the green value and 0xRR is the red value. If 0x01000000 is set in the COLORREF value (0x010000ZZ), the lower 8 bits (0xZZ) represent an index into the bitmap's palette which holds the color value. These COLORREF values can be used with any Windows function and macro that takes a COLORREF parameter.

In  Document and Medical Imaging toolkits, the COLORREF value may represent a 16 bit grayscale value if pBitmap is a 12 or 16-bit grayscale bitmap, or a 32-bit grayscale value if pBitmap is a 32-bit grayscale bitmap. So that the value is not confused with an RGB value, the COLORREF_GRAY16 mask (0x04000000) is set. In this case (0x0400YYYY), the lower 16 bits (0xYYYY) of the COLORREF value represent the 16-bit grayscale value. (0x0400FFFF is 16-bit white and 0x04000000is 16-bit black.) This is not a standard Windows value. Therefore, LEADTOOLS functions will recognize a COLORREF having this format, but Windows functions will not. For information on how to use a 16-bit grayscale COLORREF in a non-LEADTOOLS function, refer to L_GetPixelColor.

If working with 12 and 16-bit grayscale, and (crLower and crUpper) values represent the 16-bit grayscale values, then the function will work on the data. For example, to select the rage between 100 and 130:

 nValue = 100;

 rgbLo = nValue | COLORREF_GRAY16;

 nValue = 130;

 rgbHi = nValue | COLORREF_GRAY16;

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 2000 / XP/Vista.

See Also

Functions:

L_SetBitmapRgnColor, L_HolesRemovalBitmapRgn, L_SetBitmapRgnBorder

Topics:

Raster Image Functions: Creating and Using a Region

 

Defining and Using a Bitmap Region

 

Using Color Values in LEADTOOLS

 

Saving a Region

Example

 L_INT SetBitmapRgnMagicWandExample(pBITMAPHANDLE  pBitmap,
                                                   L_HWND           hWnd,
                                                   L_INT          x,
                                                   L_INT          y)
{
   L_INT nRet;
   RGNXFORM XForm;

   nRet = L_PointToBitmap(pBitmap, TOP_LEFT, &x, &y);
   if(nRet != SUCCESS)
      return nRet;
   if(L_BitmapHasRgn(pBitmap))
      nRet = L_SetBitmapRgnMagicWand(pBitmap, x, y, (20,30,15),(15,30,10), L_RGN_OR);
   else
      nRet = L_SetBitmapRgnMagicWand(pBitmap, x, y, (20,30,15),(15,30,10), L_RGN_SET);
   if(nRet == SUCCESS)
   {
      if(L_BitmapHasRgn(pBitmap))
      {
         HDC hDC=GetDC(hWnd);
         XForm.uViewPerspective=TOP_LEFT;
         XForm.nXScalarNum=1;
         XForm.nXScalarDen=1;
         XForm.nYScalarNum=1;
         XForm.nYScalarDen=1;

         XForm.nXOffset=0;
         XForm.nYOffset=0;
         L_FrameBitmapRgn(hDC, pBitmap, &XForm, 3);
         ReleaseDC(hWnd, hDC);
      }
      else
      {
         MessageBox(hWnd, TEXT("no rgn"), TEXT("error"), MB_OK);
         return nRet;
      }
   }
   return SUCCESS;
}