DelphiDabbler Code Snippets Database

Snippet Selection

The following snippets from the Code Snippets Database have been requested.

InvertBitmap (inplace overload)

Inverts the colours of bitmap ABitmap. ABitmap is updated in place. It is also converted to 24 bit pixel format if necessary.

procedure InvertBitmap(const ABitmap: Graphics.TBitmap); overload;
var
  Y: Integer;                     // loops through bitmap's scanlines
  X: Integer;                     // loops through triples in each scanline
  ByteArray: SysUtils.PByteArray; // pointer to each RGB triple
begin
  ABitmap.PixelFormat := Graphics.pf24Bit;
  for Y := 0 to ABitmap.Height - 1 do
  begin
    ByteArray := ABitmap.ScanLine[Y];
    for X := 0 to ABitmap.Width * 3 - 1 do
      ByteArray[X] := 255 - ByteArray[X];
  end;
end;

InvertBitmap (copy overload)

Inverts the colours of bitmap SrcBmp and stores the result in DestBmp. SrcBmp is not changed. DestBmp will be in 24 bit pixel format.

procedure InvertBitmap(const SrcBmp, DestBmp: Graphics.TBitmap); overload;
begin
  DestBmp.Assign(SrcBmp);
  InvertBitmap(DestBmp);
end;

View the whole database.

Go to the DelphiDabbler website.