FMXTBitmapStartLine (Delphi)

From RAD Studio XE2 Code Examples
Jump to: navigation, search

Description

This example shows how to use the TBitmap.StartLine property. This example rotates the RGB channel color of every pixel of an image.

To build and test this example, create a FireMonkey HD Application - Delphi, then add the next objects to the form:

Add the following code to the OnClick event handlers of the load button.

Code

procedure TForm1.Button2Click(Sender: TObject);
begin
    if OpenDialog1.Execute then
    begin
      Image1.Bitmap.LoadFromFile(OpenDialog1.FileName);
    end;
end;

Add the following code to the OnClick event handlers of the other button.

Code

procedure TForm1.Button1Click(Sender: TObject);
var
  MyBitmap: TBitmap;
  I: Integer;
  T: Byte;
  PixelRecs: PAlphaColorRecArray;
begin
  MyBitmap := TBitmap.Create(0, 0);
  try
    if Image1.Bitmap.IsEmpty then
      // Display a message when there is no image loaded
      MessageDlg('There is no image to customize:', TMsgDlgType.mtWarning,
        [TMsgDlgBtn.mbOk], 0)
    else
    begin
      // A copy of the initial bitmap
      MyBitmap.Assign(Image1.Bitmap);
      // Cast from 32-bit colors to color record
      PixelRecs := PAlphaColorRecArray(MyBitmap.StartLine);
      // Rotate RGB of every pixel
      for I := 0 to MyBitmap.Width * MyBitmap.Height - 1 do
        with PixelRecs[I] do
        begin
          T := R; // temp
          R := G;
          G := B;
          B := T;
        end;
      // Display the result
      Image2.Bitmap := MyBitmap;
    end;
  finally
    MyBitmap.Free
  end;
end;

The result should look like in the following image:

TBitmap StartLine proprety.PNG

Uses

See Also