![]() |
Problem mit Bitmaps
Hi allerseits,
ich habe ein TImage mit einem einfarbigen Bild. Die Farbe möchte ich beliebig ändern können. Dazu benutze ich die folgende Prozedur:
Code:
Das funktioniert auch wunderbar unter WIN32. Auf dem iPad und auch auf dem Simulator sind aber rot und blau vertauscht. Woran kann das denn liegen?
procedure TForm1.setzeBitmapFarbe(BitMap: TBitmap; NeueFarbe:TAlphaColor);
var BitmapData: TBitmapData; Pixel: PAlphaColor; I, J: Integer; begin if Bitmap.Map(TMapAccess.ReadWrite, BitmapData) then begin for J := 0 to Bitmap.Height - 1 do begin Pixel := BitmapData.GetScanline(J); for I := 0 to Bitmap.Width - 1 do begin if (TAlphaColorRec(Pixel^).R <>0) or (TAlphaColorRec(Pixel^).G <>0) or (TAlphaColorRec(Pixel^).B <>0) then begin Pixel^ := NeueFarbe; end; Inc(Pixel); end end; Bitmap.Unmap(BitmapData); end; end; |
AW: Problem mit Bitmaps
Das liegt daran das rot und blau vertauscht sind :-D
Jetzt mal Spaß beiseite: Bei mehrkanaligen Bildern ist keine Konvention zwingend vorgegeben (Reihenfolge der Kanäle "RGB" oder "BGR"; "ARGB" oder "RGBA"). D.h. vorher auswerten. Edit: ![]() TAlphaColor: ABGR |
AW: Problem mit Bitmaps
Ich bin jetzt kein Firemonkey-Experte aber wenn das Bild quasi nur eine einfarbige Fläche ist dann
kannst du doch auch einfach Canvas.FillRect (o.ä.) benutzen statt über Scanline jeden Pixel selbst umzusetzen. |
AW: Problem mit Bitmaps
Zitat:
|
AW: Problem mit Bitmaps
Zitat:
|
AW: Problem mit Bitmaps
Achso, ok dann geht das natürlich nicht.
|
AW: Problem mit Bitmaps
Zitat:
SCNR :oops: MfG |
AW: Problem mit Bitmaps
[QUOTE=pelzig;1271207]
Zitat:
|
AW: Problem mit Bitmaps
Es gibt halt bei der Byte-Order einen Unterschied ob es sich um ein BigEndian oder LittleEndian Betriebssystem handelt.
![]() |
AW: Problem mit Bitmaps
Hallo,
Hab mal etwas probiert. So ginge es auch:
Delphi-Quellcode:
Musst dann halt die entspechende Maskenfarbe übergeben. In meinem Test wars einfach weiß.
function GenerateBitmapMask(ABitmap: TBitmap; AMaskColor: TAlphaColor = TAlphaColorRec.White): PByteArray;
var Data: TBitmapData; Scan: PAlphaColorRec; i,j: Integer; begin Result := ABitmap.CreateMask; ABitmap.Map(TMapAccess.maRead, Data); try for i := 0 to ABitmap.Height-1 do begin Scan := Data.GetScanline(i); for j := 0 to ABitmap.Width-1 do begin if AMaskColor = TAlphaColor(Scan^) then Result[i*ABitmap.Width+j] := 255 else Result[i*ABitmap.Width+j] := 0; Inc(Scan); end; end; finally ABitmap.Unmap(Data); end; end; procedure SetBitmapColor(ABitmap: TBitmap; AColor: TAlphaColor; AMask: PByteArray = nil); begin ABitmap.Clear(AColor); if Assigned(AMask) then ABitmap.ApplyMask(AMask); end; procedure TForm3.Button1Click(Sender: TObject); var mask: PByteArray; begin mask := GenerateBitmapMask(Image1.Bitmap{, TAlphaColorRec.White}); try SetBitmapColor(Image1.Bitmap, TAlphaColorRec.Coral, mask); finally Dispose(mask); end; end; Du hast ja echte Transparenz. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:41 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