Thema: Delphi TBitmap32 - Alphakanal

Einzelnen Beitrag anzeigen

fui-tak

Registriert seit: 24. Okt 2008
117 Beiträge
 
Turbo Delphi für Win32
 
#3

AW: TBitmap32 - Alphakanal

  Alt 5. Aug 2010, 16:56
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 dieser Seite und von dieser), zusammengesucht.

Geändert von fui-tak ( 5. Aug 2010 um 17:00 Uhr)
  Mit Zitat antworten Zitat