FMX.AlphaColorToPixel (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to use an AlphaColorToPixel method. AlphaColorToPixel is used to add vertical lines with a specified color and distance between two lines to a specified bitmap.

Code

public
    { Public declarations }
     procedure TestAlphaColorToPixel(ABitmap: TBitmap; Color: TAlphaColor;
  Distance: integer);
procedure TForm1.Button1Click(Sender: TObject);
var
 img: TBitmap;
begin
  img:= TBitmap.Create;
  try
    img.LoadFromFile('Photo.jpg');
  finally
    TestAlphaColorToPixel(img, TAlphaColorRec.Red, 10);
    img.SaveToFile('Photo2.jpg');
    Showmessage('Image Saved');
  end;
    img.Free;
end;
procedure TForm1.TestAlphaColorToPixel(ABitmap: TBitmap; Color: TAlphaColor;
  Distance: integer);
var
  bitdata1: TBitmapData;
  I: integer;
  J: integer;
begin
  if (ABitmap.Map(TMapAccess.ReadWrite, bitdata1)) then
    try
      for I := 0 to Round(ABitmap.Width / Distance) - 1 do
        for J := 0 to ABitmap.Height - 1 do
        begin
          begin
            AlphaColorToPixel(Color, @PAlphaColorArray(bitdata1.Data)
              [J * (bitdata1.Pitch div PixelFormatBytes[ABitmap.PixelFormat])
              + Distance * I], ABitmap.PixelFormat);
          end;
        end;
    finally
      ABitmap.Unmap(bitdata1);
    end;
end;

Result example:

Input bitmap

TestAlphaColorToPixel(ABitmap, clared, 10)

Input Bitmap.png

AlphaColorToPixel result.png

Uses

See Also

Personal tools
Assistance