FMX.AlphaColorToScanline (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to use an AlphaColorToScanline method. AlphaColorToScanline is used to copy a specified number of lines from a bitmap to another bitmap.

Code

public
    { Public declarations }
    function TestAlphaColorToScanline(ABitmap: TBitmap;
  start, count: integer): TBitmap;
procedure TForm1.Button1Click(Sender: TObject);
var
 img: TBitmap;
 img2: TBitmap;
begin
  img:= TBitmap.Create;
  img2:= TBitmap.Create;
  try
    img.LoadFromFile('Photo.jpg');
  finally
    img2 := TestAlphaColorToScanline(img, 100, 100);
    img2.SaveToFile('PhotoScan.jpg');
    Showmessage('Image Saved');
  end;
    img.Free;
end;
function TForm1.TestAlphaColorToScanline(ABitmap: TBitmap;
  start, count: integer): TBitmap;
var
  bitdata1, bitdata2: TBitmapData;
begin
  Result := TBitmap.Create(Round(ABitmap.Width), Round(count));
  if (ABitmap.Map(TMapAccess.Read, bitdata1) and
    Result.Map(TMapAccess.Write, bitdata2)) then
  begin
    try
      AlphaColorToScanline(@PAlphaColorArray(bitdata1.Data)
        [start * (bitdata1.Pitch div PixelFormatBytes[ABitmap.PixelFormat])],
        bitdata2.Data, Round(Result.Height * Result.Width),
        ABitmap.PixelFormat);
    finally
      ABitmap.Unmap(bitdata1);
      Result.Unmap(bitdata2);
    end;
  end;
end;

Result example:

Input bitmap

TestAlphaColorToScanline(ABitmap, 100, 100)

(copy 100 lines, starting at line 100)

Input Bitmap.png

AlphaColorToScanline result.png

Uses

See Also