#include "ltwrappr.h"

virtual L_INT LBitmapRgn::SetRgnMagicWand(x, y, crLowerTolerance, crUpperTolerance)

L_INT x;

x coordinate

L_INT y;

y coordinate

COLORREF crLowerTolerance;

lower tolerance values

COLORREF crUpperTolerance;

upper tolerance values

Sets a region in the associated class object's bitmap based on the color found at point x, y in the region.




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


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


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


Upper tolerance values that set the upper stopping point for the region.



The function was successful.

< 1

An error occurred. Refer to Return Codes.


For color bitmaps:

If the value at pixel (x, y) is (125, 125, 125) and crLowerTolerance is (20, 30, 15) the lower stopping point is (105, 95, 110). If crUpperTolerance is (10, 25, 20), then the upper stopping point is (135, 150, 145). Pixels with values of (105, 95, 110) up to (135, 150, 145) will be included in the 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).

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.

To set the method used when combining the new and existing regions, call LBitmapRgn::SetRgnCombineMode. To determine the current method used when combining regions, call LBitmapRgn::GetRgnCombineMode.

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 only in the Document/Medical 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 the Document/Medical Imaging editions, 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 LBitmapBase::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, you must do the following if you want to select the rage between 100 and 130:

 nValue = 100;

 rgbLo = nValue | COLORREF_GRAY16;

 nValue = 130;

 rgbHi = nValue | COLORREF_GRAY16;

Required DLLs and Libraries


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


Win32, x64.

See Also


LBitmapRgn::SetRgnBorder, LBitmapRgn::SetRgnCombineMode, LBitmapRgn::GetRgnCombineMode, LBitmapRgn::SetRgnColorHSVRange, LBitmapRgn::SetRgnColorRGBRange


Raster Image Functions: Creating and Using a Region


Defining and Using a Bitmap Region


Using Color Values in LEADTOOLS


Saving a Region

<span c

L_INT LBitmapRgn__SetRgnMagicWandExample(LBitmapBase  *pBitmap, HWND hWnd,  
                                                          L_INT x, L_INT y) 
   L_INT nRet; 
   LPaint LeadPaint ;  
   LBitmapRgn LeadRegion(pBitmap);  
   RGNXFORM Xform;  
   HDC hDC=NULL;  
   nRet =pBitmap->PointToBitmap(TOP_LEFT, &x, &y); 
   if(nRet !=SUCCESS) 
      return nRet; 
   nRet =LeadRegion.SetRgnMagicWand(x, y, (20,30,15),(15,30,10)); 
   if(nRet !=SUCCESS) 
      return nRet; 
   Xform.uViewPerspective = TOP_LEFT;  
   hDC = GetDC(hWnd);  
    LeadPaint.SetDC(hDC) ;  
   LeadPaint. FrameRgn(L_FRAME_MOVING0,&Xform) ;  
   ReleaseDC(hWnd, hDC);  
   return SUCCESS; 
Help Version 21.0.2020.8.25
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help