Mega Code Archive

 
Categories / Delphi / Graphic
 

Flipping an image

Title: Flipping an image Question: How to flip an image? Answer: //Title: How to flip an image fast? //Category: Images //Uploader: Maarten de Haan (M.deHaan@inn.nl) //Delphi: 3, 4 and 5 (verified) //Platform: NT and W95 (verified) //================================================ Procedure Flip1Click(Sender: TObject); Var DummyImage : TImage; X,Y : Integer; SrcRect,DstRect : TRect; Begin //Assumes that Image1 holds the picture to be flipped X := Image1.Picture.Width; Y := Image1.Picture.Height; SrcRect := Rect(0,0,X,Y); DstRect := Rect(X,0,0,Y); //This is the trick! DummyImage := TImage.Create(Self); DummyImage.Width := X; DummyImage.Height := Y; //DummyImage.Canvas.CopyMode := cmSrcCopy DummyImage.Canvas.CopyRect(DstRect,Image1.Canvas,SrcRect); //Flipping the image Image1.Picture := DummyImage.Picture; //Copy the flipped image to Image1 DummyImage.Free; //Free the dummy End;