Mega Code Archive

 
Categories / Delphi / Graphic
 

How to invert an image

Title: How to invert an image function InvertBitmap(MyBitmap: TBitmap): TBitmap; var x, y: Integer; ByteArray: PByteArray; begin MyBitmap.PixelFormat := pf24Bit; for y := 0 to MyBitmap.Height - 1 do begin ByteArray := MyBitmap.ScanLine[y]; for x := 0 to MyBitmap.Width * 3 - 1 do begin ByteArray[x] := 255 - ByteArray[x]; end; end; Result := MyBitmap; end; procedure TForm1.Button1Click(Sender: TObject); begin Image1.Picture.Bitmap := InvertBitmap(Image1.Picture.Bitmap); Image1.Refresh; end;