Re: [GELÖST]: Bilder/Bitmaps transparent in eine PaintBox la
es funktioniert, und das ist (für mich) die Hauptsache! :thumb:
|
Re: [GELÖST]: Bilder/Bitmaps transparent in eine PaintBox la
Etwas langsam aufgrund des pixelweisen Zeichnens auf der PaintBox und BitBlt geht da leider nicht, aber sonst geht der folgende Code bei mir. :lol:
Delphi-Quellcode:
Die Farbe des oberen linken Pixels wird als transparente Farbe genommen.
procedure DrawTransparent(ImgList: TImageList; ImgLIndex: Integer; PaintBox: TPaintBox);
// some crazy declarations type TRGB = packed record R, G, B: Byte; end; type TLine = array[0..0] of TRGB; var MyBitmap: TBitmap; x, y: Integer; PLine: ^TLine; PixelColor, TranspColor: TColor; begin MyBitmap := TBitmap.Create; try MyBitmap.PixelFormat := pf24bit; // get bitmap from the TImageList ImgList.GetBitmap(ImgLIndex, MyBitmap); // the transparant color is in the upper left corner TranspColor := MyBitmap.Canvas.Pixels[0, 0]; // read pixels from the bitmap for y := 0 to MyBitmap.Height - 1 do begin for x := 0 to MyBitmap.Width - 1 - 1 do begin PLine := MyBitmap.ScanLine[y]; // check if the color of the current pixel is TranspColor PixelColor := RGB(PLine[x].R, PLine[x].G, PLine[x].B); // draw pixels on the TPaintBox.Canvas if PixelColor <> TranspColor then begin PaintBox.Canvas.Pixels[x, y] := PixelColor; end; end; end; finally FreeAndNil(MyBitmap); end; end; Aufruf:
Delphi-Quellcode:
Das ist mehr zum Spaß und bei großen Bilder vermutlich nicht sehr schnell.
DrawTransparent(ImageList1, 0, PaintBox1);
Grüße, Matze |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:35 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz