Examining and Altering Bitmaps

You can make many changes to the bitmap in memory, but keep in mind that the changes do not appear on the screen until the image repaints.

Getting Bitmap Information

Get information about the bitmap from the following properties and method:

BitmapBits property

BitmapHeight property

BitmapWidth property

BitmapXRes property

BitmapYRes property

IsGrayscale property

IsSigned property

GetColorCount method

GrayscaleExt method

ConvertToColoredGray method

Getting and Setting Pixel Values

Use the following method to get and set the values of individual pixels:

Pixel property

Fill method

Changing the Data Format

Use the following methods to change the bits per pixel and palette of a bitmap or bitmap list:

ColorRes method

ColorResList method

Use the following methods to change a bitmap to 8-bit grayscale or to a 1-bit halftone:

Grayscale method

Halftone method

Bitmap data can be signed or unsigned. If the bitmap data is signed, image processing and paint functions may not work correctly. A bitmap will not be loaded signed unless the LoadSigned property is set to TRUE before loading the image. To determine whether the bitmap loaded into the control is signed or not, check the IsSigned property. If this property is TRUE, the bitmap data is signed and should be converted to unsigned by calling the ConvertSignedToUnsigned method.

Windows always uses the RGB color-space model, and when loading or saving a file, LEADTOOLS converts image data to or from RGB, as necessary. Nevertheless, LEADTOOLS lets you create and merge color separations using a number of color-space models, including RGB, CMYK, CMY, HSV, and HLS. Use the ColorSeparate method to create separations, use the ColorMerge method to merge separations, and use the ColorPlanes property to access the separated planes.

Updating the Line Profiles

LineProfile method

LineProfileSize property

LineProfileRed property

LineProfileGreen property

LineProfileBlue property

Doing Geometric Transformations

Geometric transformations include resizing, trimming, rotating, shearing, flipping, or reversing a bitmap. The following geometric transformation functions are designed mainly for document imaging:

AutoTrim method

Deskew method (Document/Medical only)

FastRotate method (Document/Medical only)

Use the following method to resize the bitmap. Keep in mind that this changes the amount of memory required for the bitmap, and it is not necessary to do this for zooming in or out.

Size method

Use the following methods to alter a bitmap in various ways:

Trim method

Rotate method

Shear method

Flip method

Reverse method

LEADTOOLS also provides the TransformFile method for performing lossless flips, rotations and reversals. However, only certain file formats are supported at this time. This function provides better results than loading an image, transforming it using the Rotate method, Flip method or Reverse method and then resaving it. For each marker that the TransformFile method encounters within a file, the TransformMarker event is triggered. Within this event the user sets the WriteMarkerAction property to indicate what action to take with the marker. If the marker is to be written to the output file, the user calls the WriteMarker method.

Lightening, Darkening, Filtering, and So Forth

A number of image processing functions let you change the values of pixels across a bitmap (or a region in the bitmap) using various algorithms and filters. You might do this to improve the appearance of the image, to analyze details in the image, or to apply artistic effects. The following topics provide details:

Changing Brightness and Contrast

Removing Noise

Detecting and Enhancing Edges and Lines

Applying Artistic Effects

Correcting Colors

Adding Another Image to a Bitmap

The Combine method lets you add all or part of another bitmap to the target bitmap. You can pass flags to control whether the new pixels simply replace the old ones or are combined with the old ones in a specified way. You can also define a region in the target bitmap, and if you do, the function affects only the specified region. For information about regions, refer to Creating and Using a Bitmap Region. For more information on combining images, refer to Combining Images.

The Underlay method also combines images, but it has a much more specific purpose. It combines two bitmaps so that one appears to be an underlying texture for the other.

Treating the bitmap as a device context opens up many possibilities. You can set the DrawPersistence property to TRUE to draw text or objects on the bitmap. For details, refer to Drawing Simple Objects and Drawing Three-Dimensional Shapes and Text.

Also, the GetBitmapDC method lets you access the bitmap as a device context. You can then use Windows GDI functions to draw lines, text, or images on the bitmap. For more information, refer to Using the Windows API.

To replace an image with an image created from images in a specified directory, use the Picturize method.

Window leveling (Medical Imaging only)

Window leveling is only valid for 12 and 16-bit grayscale images and is used to map grayscale intensities by specifying the bit range and/or a user defined color map. The bit range is specified by LevelLowBit property and LevelHighBit property. The user defined color map is defined by LevelLUT property. The LevelLUT property can be filled by calling the WindowLevelFillLUT method. This method maps grayscale intensities to a specific color range. The LevelLowBit property, LevelHighBit property and LevelLUT property will only affect the way the image is painted and will not affect the image data. To affect the image data, you must call the WindowLevel method. The WindowLevelBitmap property determines whether the WindowLevel method creates a new 8 or 24-bit bitmap, or leaves the bitmap as a 12 or 16-bit grayscale. The WindowLevel method applies window leveling to the bitmap, and resets LevelLowBit property, LevelHighBit property, LevelLUTLength property and LevelLUT property if a new 8 or 24-bit bitmap is created. LevelLowBit property and LevelHighBit property indicate which bits are considered image data. LevelLUT is a remapping palette that provides the colors to use when remapping the image. MinBit property, MaxBit property, MinVal property and MaxVal property can aid in setting up the LevelLUT by providing information concerning the bitmap. These values are retrieved using GetMinMaxBits method and GetMinMaxVal method. For more information, refer to the individual entries for the properties and methods.