Available in the LEADTOOLS Imaging toolkit. |
Creating and Using a Bitmap Region
A bitmap region is an area of interest within a bitmap. A bitmap can have only one region at a time, but the region can be complex, including, for example, multiple noncontiguous shapes.
When a bitmap has a region, the LEADTOOLS methods that modify the pixel values (for example Posterize method) act on the region, rather than the whole bitmap. For a list of these methods, refer to Raster Images: Where the Region Preempts the Bitmap.
In addition, the LEADTOOLS methods that flip, reverse, rotate, shear, or resize a bitmap also transform the region to match the bitmap. For example, if you were to shear a bitmap that had a rectangular region, the region would become a parallelogram. For a list of these methods, refer to Raster Images: Methods That Transform the Region and the Bitmap.
By default, a bitmap does not have a region. You can create a simple bitmap region using the RgnMarkingMode property, which automates region creation. You can create a more complex bitmap region by calling one or more of the SetRgn... methods. Each time you call one of these methods, you specify how the new region is to be added to the existing bitmap region (if there is one). For a description of the possibilities, refer to Flags for Setting a Region.
To create a new region, or update an existing region, based on either an HSV range or an RGB range, use SetRgnColorHSVRange method or the SetRgnColorRGBRange method. To convert between HSV and RGB color space, use the following:
RGBfromHSV method
Automatic Creation of a Region
Use the RgnMarkingMode property to enable automatic creation of a region, based on MouseDown, MouseMove, and MouseUp events. This method supports creation of a rectangle, rounded rectangle, ellipse, or freehand region. It automatically handles scaling differences between the displayed image and the bitmap. On the MouseDown event, it begins outlining where the region will appear on the screen. It updates the outline on each MouseMove event. Then, on the MouseUp event, it deletes the displayed outline and creates the bitmap region. To make an outline of the region visible at that point, you must set the RgnFrameType property.
The following event occurs each time the bitmap region is created or updated. It is especially useful with the RgnMarkingMode property, which automates the creation of regions.
Use the following property to display an outline of the current region:
Creating and Using a Floater
A floater is an additional bitmap that is associated with the LEAD control. Its common application is to implement the interactive visual aspects of an outline-drag-and-paste operation. You use it to get a copy of the image in the current bitmap region, which the user can drag to another position in the LEAD control's client area.
The following property lets you create the floater bitmap by assigning the LEAD control's Bitmap property to it. The floater bitmap that this creates is the size of the bounding rectangle of the main bitmap's region, and it contains the same region as the main bitmap.
The following property lets you display or hide the floater:
If you want to paste a floater into a new position, you must assign the floater to a second LEAD control, move the first LEAD control's region to the floater's position, then use the Combine method to paste the second control's bitmap at that position. The region acts as a mask with the combine operation.
The following method lets you see whether a point in the LEAD control's client area is in the floater. It is commonly used in the MouseDown event to test whether the mouse click selects the floater.
Use the following methods to position and size the display of the floater by setting destination rectangles. These methods are commonly used in the MouseMove event to reposition the floater in the LEAD control's client area. If the floater is visible, its region is automatically repainted when you set the destination rectangle. If the AutoSetRects property is set to True, the destination rectangle defaults to the size of the floater bitmap, and the clipping rectangle defaults to the size of the LEAD control's client area. Therefore, you must set the destination rectangle to the desired position, but you do not have to set the clipping rectangle unless you want to display only part of the floater.
Use the following properties to get the current destination rectangles of the floater. (You can also set these properties, but the floater will repaint each time you set one of the properties.)
Use the following read-only properties to get the size of the floater bitmap:
If you want to paste a floater into a new position, you must assign the floater to a second LEAD control, move the first LEAD control's region to the floater's position, then use the Combine method to paste the second control's bitmap at that position. The region acts as a mask with the combine operation.
Storing, Retrieving, and Deleting Regions
Use the following methods to store a copy of the region from the floater or main bitmap, and to delete the stored region when you no longer need it. Keep in mind that the region data contains only positioning information, not the bitmap's pixel values.
Use the following method to remove the current bitmap region and free the region data from memory:
Use the following method to add a stored region to the current bitmap region. You can either replace the current region or create a complex region by setting a Boolean flag that determines how the added region interacts with the existing region.
Getting Region Information
Use the following methods and properties to get information about the current bitmap region.
Rows within a region can have 0, 1, or more segments per row. To get the segments contained within the region for a particular row, call the GetBitmapClipSegments method.
Low-Level Methods for Creating Regions
Use the following methods to add a new region to the bitmap. You can either replace the current region or create a complex region by setting a Boolean flag that determines how the added region interacts with the existing region. For a description of the possibilities, refer to Flags for Setting a Region.
The coordinates that you use with these methods are relative to the LEAD bitmap in memory, not to the client area.
These methods are for a new region with a simple shape:
This method is for a new region that consists of all pixels of a specified color:
Use the SetRgnMagicWand method to set a region based on the color of a specified point.
These methods are for a new polygonal region. You build an ordered array of points for the vertices of the polygon; then create the region based on the array. The PolygonSize property specifies the size of the array. You can either specify a large array to start with, or you can increase the size of the array when necessary (without losing the existing points).
LEADTOOLS also provides a number of methods and properties for creating a curve region or adding a curve region to an existing bitmap region. To create a curve region, first build an ordered array of points for the curve. Then create the region based on the array. The CurveSize property specifies the size of the array. Either specify a large array to start with, or increase the size of the array as needed, without losing existing points. For each point, update the following indexed properties:
and define the characteristics of the curve by setting the following properties:
Then call the SetRgnCurve method to add the region to the bitmap.
A standard curve can be converted to a series of Bezier points using the CurveToBezier method. This method updates the following properties with information about the Bezier points created:
Moving a Region
Use the following method to move the current bitmap region. The values that you use are relative to the LEAD bitmap in memory, not to the client area.
Coloring a Region
Set the RgnFrameColor property to display a filled, color representation of a region.
Resizes the Bitmap Region