
Search
|
| |
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:
- 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.
- User can select the blend color using TColorDialog.
- 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).
- 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.
- 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.
Further Explorations
Why
is my ScanLine implementation only 4 times faster than Pixel operations?
Bug in the program? |
|
 |
|
Created: September 21, 2013 |
Modified:
May 15, 2018
|
|