VCL.ImageProc Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to use TImage, TBitmap, and other related components to manipulate characteristics of images, including contrast, negatives, and arithmetic operations.


You can find the ImageProcessing sample project at:

  • Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to CPP\VCL\ImageProc
  • Subversion Repository:
    • You can find C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.


This sample consists of an image editor. You can open up to three images at the same time and perform operations on them: adjust the brightness and contrast, flip the image, apply filters and effects, calculate the sum, difference, and average of two images.

How to Use the Sample

  1. Navigate to Start | Programs | Embarcadero RAD Studio Athens | Samples and open ImageProcessing.cbproj.
  2. Press F9 or choose Run > Run.


File Contains


The form for the about box to be displayed from the Help menu.


The form displayed when the user chooses to add, subtract, or calculate the average of two images.


The dialog displayed to adjust the brightness and contrast.


Global functions necessary to manipulate images.


The form for the editor itself.


The form displayed when the user chooses to adjust the threshold.


  • TForm5 represents the class for the about box that is displayed from the Help menu.
  • TForm3 represents the class for the brightness/contrast form.
  • TForm1 implements the main form. It handles the visual and nonvisual components and the occurring events.
  • TForm4 implements the class for the threshold form.


  • To select a line of pixels in an image, the TBitmap.ScanLine property is used, which returns an array of values. If the image is in grayscale, the array has the same length as the image width. If the image is in color, the array has 3 times the image width, each pixel being represented by three values – blue, green, and red, in that order.
  • The Sobel and Sobel2 methods implement the sobel operator used in edge detection. In this application, edge detection is used to create the drawing and detailed drawing effects.
  • addImage, subtractImage, and averageImage apply only to two grayscale images and calculate the sum, difference, or average of pixels in corresponding positions in the two images.
  • To adjust the brightness and contrast of an image, a linear transformation is applied to every pixel.
  • The auto-contrast is set by stretching the histogram.
  • For the old picture effect, every pixel is first converted to its gray correspondent, therefore blue, green, and red will have the same value. Then, a tone of yellow is added by subtracting a constant from the blue value.



See Also