Thursday, September 10, 2009

Invert a bitmap

How to invert a bitmap
function BitmapInvert(ABitmap: TBitmap): TBitmap;
var
  x, y: Integer;
  ByteArray: PByteArray;
begin
  ABitmap.PixelFormat := pf24Bit;
  for y := 0 to ABitmap.Height - 1 do begin
    ByteArray := ABitmap.ScanLine[y];
    for x := 0 to ABitmap.Width * 3 - 1 do begin
      ByteArray[x] := 255 -ByteArray[x];
    end;
  end;
  Result := ABitmap;
end;

Usage
 myBitmap := BitmapInvert(aBitmapVariable{or myBitmap});

No comments:

Post a Comment

Blogroll(General programming and Delphi feeds)