Blend Drawing Demo

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

My British friend, George, has provided material for three projects this month (September, 2013). Here is a "Delphi Techniques" program which explores his latest problem: semi-transparent shading of a selected quadrant of a TImage bitmap.   The image and shading options he requested are displayed on the initial "Blend Demo" page of the program.

The code was derived from our DFF Graphics Effects program which blends two overlapped images. In this case, one of the images was replaced by a single color (gray in George's case) and blended 50-50 with the selected quadrant.   The trick is to adjust the level of each of the three basic colors, Red, Green, and Blue for each pixel in the rectangle to be blended .  If pixel P[x,y] is to be blended and R1,G1,B1 are the RGB colors for Image1, R2, G2, B2 the RGB colors for our blended color, and T is the fraction of the blend color to be used then then new colors R1:=(1-T)*R1 + T*R2 with the same for G and B colors.;  

That was almost too easy so, in addition to solving the initial problem, the program provided an opportunity to explore a number
of extensions including:

  1. Other BMP or JPEG images can be loaded for testing. In addition to George's   A1.bmp file (44x50) I have included medium sized (247x212) 4InARow3.jpg and large (417x364) Books.jpg in the downloads.   
  2. User can select the blend color using TColorDialog.
  3. User can change the level of the blend color to be applied to the blended area. 0% (blend color invisible) to 100% (shaded image area completely hidden by the blend color).
  4. Pixel by pixel processing can be very slow for larger images. The program provides  the "Scanline" property of TBitmaps to  reduce the time to apply blending. A "Performance Test" button allows comparing the speed of each method.  It seems that ScanLine blending is only about 4 times faster than Pixel level blending which was a bit disappointing.
  5. In addition to specifying the quadrant to be shaded, users can click and drag to move the shaded area in one of two ways. Dragging the shaded area directly is very jerky and slow for a larger image when Pixel based blending is applied. An option is available to drag an outline only provides acceptable speed under those conditions. The shaded area is then relocated to the outline location when the dragged outline is dropped.

The source code is well commented if you want the details.  As usual, let me know if you have questions.

bulletDownload source 
bulletDownload executable

Further Explorations

Why is my ScanLine implementation only 4 times faster than Pixel operations?  Bug in the program?  
 

 

Created: September 21, 2013

Modified: February 18, 2016

 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.