2011. február 8., kedd

How to flip a bitmap (fast)


Problem/Question/Abstract:

How to flip a bitmap (fast)

Answer:

procedure Flip1Click(Sender: TObject);

var
  DummyImage: TImage;
  X, Y: Integer;
  SrcRect, DstRect: TRect;

begin
  //Assumes that Image1 holds the bitmap to be flipped
  X := Image1.Picture.Bitmap.Width;
  Y := Image1.Picture.Bitmap.Height;
  SrcRect := Rect(0, 0, X, Y);
  DstRect := Rect(X, 0, 0, Y); // <===== Mark this !!!
  DummyImage := TImage.Create(Self);
  DummyImage.Picture.Bitmap.Width := X;
  DummyImage.Picture.Bitmap.Height := Y;
  //DummyImage.Canvas.CopyMode := cmSrcCopy
  DummyImage.Picture.Bitmap.Canvas.CopyRect(DstRect, Image1.Picture.Bitmap.Canvas,
    SrcRect);
  // Write it back to the original bitmap
  Image1.Picture.Bitmap.Assign(DummyImage.Picture.Bitmap);
  DummyImage.Free;
end;

Nincsenek megjegyzések:

Megjegyzés küldése