gpt4 book ai didi

delphi - 如何将FMX.Graphics.TBitmap转换为VCL.Graphics.TBitmap或Vcl.Imaging.PngImage.TPngImage?

转载 作者:行者123 更新时间:2023-12-03 15:56:09 32 4
gpt4 key购买 nike

如何将 FMX.Graphics.TBitmap 转换为 VCL.Graphics.TBitmap 或 Vcl.Imaging.PngImage.TPngImage?

我的项目中有FMX表单和VCL表单。

最佳答案

感谢David Heffernan和一些搜索我编写了这些函数如下。

我首先想出了不支持Alpha的函数

function ConvertFmxBitmapToVclBitmap(b:FMX.Graphics.TBitmap):Vcl.Graphics.TBitmap;
var
data:FMX.Graphics.TBitmapData;
i,j:Integer;
AlphaColor:TAlphaColor;
begin
Result:=VCL.Graphics.TBitmap.Create;
Result.SetSize(b.Width,b.Height);
if(b.Map(TMapAccess.Readwrite,data))then
try
for i := 0 to data.Height-1 do begin
for j := 0 to data.Width-1 do begin
AlphaColor:=data.GetPixel(i,j);
Result.Canvas.Pixels[i,j]:=
RGB(
TAlphaColorRec(AlphaColor).R,
TAlphaColorRec(AlphaColor).G,
TAlphaColorRec(AlphaColor).B);
end;
end;
finally
b.Unmap(data);
end;
end;

我编写了第二个函数来转换 FMX.Graphics.TBitmapVcl.Imaging.PngImage.TPngImage并且它支持Alpha。

function ConvertFmxBitmapToPng(b:FMX.Graphics.TBitmap):Vcl.Imaging.PngImage.TPngImage;
var
data:FMX.Graphics.TBitmapData;
i,j:Integer;
AlphaColor:TAlphaColor;
AlphaLine:VCL.Imaging.PngImage.pByteArray;
begin
result:=TPngImage.CreateBlank(COLOR_RGBALPHA, 8, b.Width, b.Height);;
if(b.Map(TMapAccess.Readwrite,data))then
try
for i := 0 to data.Height-1 do begin
AlphaLine:=Result.AlphaScanline[i];
for j := 0 to data.Width-1 do begin
AlphaColor:=data.GetPixel(j,i);
AlphaLine^[j]:=TAlphaColorRec(AlphaColor).A;
Result.Pixels[j,i]:=
RGB(
TAlphaColorRec(AlphaColor).R,
TAlphaColorRec(AlphaColor).G,
TAlphaColorRec(AlphaColor).B);
end;
end;
finally
b.Unmap(data);
end;
end;

关于delphi - 如何将FMX.Graphics.TBitmap转换为VCL.Graphics.TBitmap或Vcl.Imaging.PngImage.TPngImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36823042/

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