Reputation: 21
In firemonkey xe5, when I save a transparent PNG image into bitmap its transparency become black. How can I change into white?
I just use:
Image1.bitmap.loadfromfile('IMG.png');
image1.bitmap.Savetofile('image.BMP');
Upvotes: 2
Views: 1482
Reputation: 1276
This isn't a complete solution but it will get you started. You will need to tweak the A, R, G, B values to get what you want.
procedure ApplyNoAlphaEdge(ABitmap: TBitmap; OpacityThreshold: integer);
var
bitdata1: TBitmapData;
I: integer;
J: integer;
C: TAlphaColor;
begin
if (ABitmap.Map(TMapAccess.maReadWrite, bitdata1)) then
try
for I := 0 to ABitmap.Width - 1 do
for J := 0 to ABitmap.Height - 1 do
begin
begin
{$IF DEFINED(VER270) OR DEFINED(VER280) OR DEFINED(VER290)}
C := PixelToAlphaColor(@PAlphaColorArray(bitdata1.Data)
[J * (bitdata1.Pitch div PixelFormatBytes[ABitmap.PixelFormat])
+ 1 * I], ABitmap.PixelFormat);
{$ELSE}
C := PixelToAlphaColor(@PAlphaColorArray(bitdata1.Data)
[J * (bitdata1.Pitch div GetPixelFormatBytes(ABitmap.PixelFormat))
+ 1 * I], ABitmap.PixelFormat);
{$ENDIF}
if TAlphaColorRec(C).A<OpacityThreshold then
begin
TAlphaColorRec(C).A := 0;
TAlphaColorRec(C).R := 255;
TAlphaColorRec(C).G := 255;
TAlphaColorRec(C).B := 255;
{$IF DEFINED(VER270) OR DEFINED(VER280) OR DEFINED(VER290)}
AlphaColorToPixel(C, @PAlphaColorArray(bitdata1.Data)
[J * (bitdata1.Pitch div PixelFormatBytes[ABitmap.PixelFormat])
+ 1 * I], ABitmap.PixelFormat);
{$ELSE}
AlphaColorToPixel(C, @PAlphaColorArray(bitdata1.Data)
[J * (bitdata1.Pitch div GetPixelFormatBytes(ABitmap.PixelFormat))
+ 1 * I], ABitmap.PixelFormat);
{$ENDIF}
end;
end;
end;
finally
ABitmap.Unmap(bitdata1);
end;
end;
Upvotes: 5