![]() |
TBitmap32 - Alphakanal
Hallo,
ich versuche gerade einen Alphakanal in einer TBitmap32 zu erschaffen, aber leider finde ich nichts brauchbares und die Hilfe hilft mir auch nicht weiter. Ich würde gerne einfach eine bestimmte Farbe als transparent definieren und dann alle Pixel, die diese Farbe haben, mittels Alphakanal, transparent machen. Das anschließende abspeichern als .tga Datei ( ![]() Wer kann mir ein paar Tipps geben? |
AW: TBitmap32 - Alphakanal
Einfach das Alpha-Byte z.B. beim Speichern abhängig von der Farbe setzen.
Delphi-Quellcode:
var
Transparent: TRGBA; {...} for i := 0 to (bmp32.Width * bmp32.Height) - 1 do begin Color32ToRGBA(P^ , c.r, c.g, c.b, c.a); DataBuffer[n] := c.B; inc(n); DataBuffer[n] := c.G; inc(n); DataBuffer[n] := c.R; inc(n); if (c.B = Transparent.B) and (c.g = Transparent.g) and (c.r = Transparent.r) then DataBuffer[n] := {Wert für 100% Transparent} else DataBuffer[n] := {Wert für 0% Transparent}; inc(n); inc(P); end; |
AW: TBitmap32 - Alphakanal
Vielen Dank für die Antwort, aber ich habe gerade selbst eine Lösung gefunden und wollte das hier posten und dann hat doch jemand Hilfe für mich ^^
Für alle, die das gleiche Problem haben, hier einmal meine Lösung. Dann könnt ihr euch zwischen einem der beiden Lösungwege entscheiden.
Delphi-Quellcode:
var btmp:TBitmap32;
... procedure TForm1.Button1Click(Sender: TObject); begin btmp := TBitmap32.Create; btmp.Assign(Image1.picture.bitmap);//ich lade das Bild aus einer TImage Komponente macheTransparent(btmp,255,255,255);//hier werden alle Pixel mit der Farbe 255,255,255 (also Weiß) Transparent gemacht end; procedure TForm1.ChromaKey(ABitmap: TBitmap32; TrColor: TColor32); // former CromaKey <v1.8.3 var P: PColor32; C: TColor32; I: Integer; begin TrColor := TrColor and $00FFFFFF; // erase alpha, (just in case it has some) with ABitmap do begin P := PixelPtr[0, 0]; for I := 0 to Width * Height - 1 do begin C := P^ and $00FFFFFF; // get RGB without alpha if C = TrColor then // is this pixel "transparent"? P^ := C; // write RGB with "transparent" alpha back into the SrcBitmap Inc(P); // proceed to the next pixel end; end; end; procedure TForm1.macheTransparent(ABitmap: TBitmap32;rot,gruen,blau:byte); var AColor32: TColor32; begin TColor32Entry(AColor32).A := 0;//0 Transparent, 255 komplett nicht Transparent; macht bei meinem Test aber keinen Unterschied TColor32Entry(AColor32).R := rot; TColor32Entry(AColor32).G := gruen; TColor32Entry(AColor32).B := blau; ChromaKey(ABitmap,AColor32); end; Den Code hab ich mir, ausgehend von graphics32.org (einmal von ![]() ![]() |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:40 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz