Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
Delphi 10.2 Tokyo Professional
|
AW: Problem mit Bitmaps
5. Sep 2014, 15:34
Hallo,
Hab mal etwas probiert. So ginge es auch:
Delphi-Quellcode:
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;
Musst dann halt die entspechende Maskenfarbe übergeben. In meinem Test wars einfach weiß.
Du hast ja echte Transparenz.
Michael "Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
Geändert von Neutral General ( 5. Sep 2014 um 15:40 Uhr)
|