gpt4 book ai didi

delphi - Firemonkey PNG 转位图

转载 作者:行者123 更新时间:2023-12-02 03:33:56 24 4
gpt4 key购买 nike

在firemonkey xe5中,当我将透明PNG图像保存到位图中时,其透明度变为黑色。怎样才能变成白色?

我只是使用:

Image1.bitmap.loadfromfile('IMG.png');
image1.bitmap.Savetofile('image.BMP');

最佳答案

这不是一个完整的解决方案,但它可以帮助您入门。您需要调整 A、R、G、B 值以获得您想要的结果。

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;

关于delphi - Firemonkey PNG 转位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30768400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com