FMX.Float4ToPixel (Delphi)
Contents
Description
This example shows how to use a Float4ToPixel method. Float4ToPixel is used to merge two specified bitmaps, by adding vertical lines from the second bitmap to the first one. The parameters of the next method specify the two bitmaps to be merged, the distance between two consecutive lines, and the height of the lines to be added.
Code
public
{ Public declarations }
procedure TestFloat4ToPixel(DestBitmap, ScrBitmap: TBitmap;
Distance, LineHeigth: integer);
procedure TForm1.Button1Click(Sender: TObject);
var
ImgSource: TBitmap;
ImgDestination: TBitmap;
begin
ImgSource := TBitmap.Create;
ImgDestination := TBitmap.Create;
try
ImgSource.LoadFromFile('PhotoSource.jpg');
ImgDestination.LoadFromFile('PhotoDestination.jpg');
finally
TestFloat4ToPixel(ImgDestination, ImgSource, 50, 30);
ImgDestination.SaveToFile('PhotoResult.jpg');
ShowMessage('Image Saved');
end;
ImgSource.Free;
ImgDestination.Free;
end;
procedure TForm1.TestFloat4ToPixel(DestBitmap, ScrBitmap: TBitmap;
Distance, LineHeigth: integer);
var
bitdata1, bitdata2: TBitmapData;
I: integer;
J: integer;
K: integer;
begin
if (DestBitmap.Map(TMapAccess.Write, bitdata1) and
ScrBitmap.Map(TMapAccess.Read, bitdata2)) then
try
for I := 0 to DestBitmap.Width - 1 do
for J := 0 to Round(DestBitmap.Height / Distance) - 1 do
begin
for K := 0 to LineHeigth do
Float4ToPixel
(TAlphaColorF.Create(PixelToAlphaColor(@PAlphaColorArray
(bitdata2.Data)[(J * Distance + K) *
(bitdata1.Pitch div PixelFormatBytes[ScrBitmap.PixelFormat]) + I],
ScrBitmap.PixelFormat)), @PAlphaColorArray(bitdata1.Data)
[(J * Distance + K) * (bitdata1.Pitch div PixelFormatBytes
[DestBitmap.PixelFormat]) + I], DestBitmap.PixelFormat);
end;
finally
DestBitmap.Unmap(bitdata1);
ScrBitmap.Unmap(bitdata2);
end;
end;
Result example:
Destination bitmap |
Source bitmap |
TestFloat4ToPixel(DestBitmap, ScrBitmap,50,20) |
Uses
- FMX.Types.Float4ToPixel ( fr | de | ja )
- FMX.Graphics.TBitmap.Map( fr | de | ja )
- FMX.Graphics.TBitmap.Unmap( fr | de | ja )
See Also
- FMX.Types.TPixelFormat ( fr | de | ja )