whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1548)

Database (90)
Files (137)
Forms (107)
Graphic (116)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

20 Visitors Online


 
...invert a Bitmap?
Autor: Katja Hoffmann
Homepage: http://www.katjahoffmann.gmxhome.de
[ Print tip ]  

Tip Rating (3):  
     


function InvertBmp1(SourceBmp: TBitmap): TBitMap;
var
  
i, j: Longint;
  tmp: TBitMap;
  red, green, blue: Byte;
  PixelColor: Longint;
begin
  
tmp := TBitmap.Create;
  tmp.Width  := SourceBmp.Width;
  tmp.Height := SourceBmp.Height;
  for i := 0 to SourceBmp.Width - 1 do
  begin
    for 
j := 0 to SourceBmp.Height - 1 do
    begin
      
PixelColor := ColorToRGB(SourceBmp.Canvas.Pixels[i, j]);
      red := PixelColor;
      green := PixelColor shr 8;
      blue := PixelColor shr 16;
      red  := 255 - red;
      green := 255 - green;
      blue := 255 - blue;
      tmp.Canvas.pixels[i, j] := (red shl 8 + green) shl 8 + blue;
    end;
  end;
  Result := tmp;
end;

function InvertBmp2(ABitmap : TBitmap) : TBitmap;
var
  
l_bmp : TBitmap;
begin
  
l_bmp := TBitmap.Create;
  l_bmp.Width := ABitmap.Width;
  l_bmp.Height := ABitmap.Height;
  l_bmp.PixelFormat := ABitmap.PixelFormat;
  BitBlt( l_bmp.Canvas.Handle, 0, 0, l_bmp.Width, l_bmp.Height,
    ABitmap.Canvas.Handle, 0, 0, SRCINVERT );
  result := l_bmp;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners