VCL.Bitmap到FMX.Bitmap [英] VCL.Bitmap To FMX.Bitmap
本文介绍了VCL.Bitmap到FMX.Bitmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Web上找到了This代码,但FMX.Bitmap没有扫描线。 是否可以以某种方式将VCL.TBitmap复制或绘制为FMX.Bitmap?
{$IFDEF MSWINDOWS}
type
TBitmap = FMX.Types.TBitmap;
TVclBitmap = Vcl.Graphics.TBitmap;
procedure TakeScreenshot(Dest: FMX.Types.TBitmap);
var
DC: HDC;
Size: TPointF;
VCLBitmap: TVclBitmap;
Y: Integer;
begin
VCLBitmap := nil;
//Size := FMX.Platform.IFMXScreenService.GetScreenSize;
DC := GetDC(0);
try
VCLBitmap := TVclBitmap.Create;
VCLBitmap.PixelFormat := pf32bit;
VCLBitmap.SetSize(Trunc(Size.X), Trunc(Size.Y));
BitBlt(VCLBitmap.Canvas.Handle, 0, 0, VCLBitmap.Width, VCLBitmap.Height,
DC, 0, 0, SRCCOPY);
Dest.SetSize(VCLBitmap.Width, VCLBitmap.Height);
{ The format of a FMX bitmap and a 32 bit VCL bitmap is the same, so just
copy the scanlines. - not true- FMX bitmap does not have ScanLine? }
for Y := Dest.Height - 1 downto 0 do
Move(VCLBitmap.ScanLine[Y]^, Dest.ScanLine[Y]^, Dest.Width * 4);
{Dest.Canvas.DrawBitmap(); Not possible to assign or draw}
finally
ReleaseDC(0, DC);
VCLBitmap.Free;
end;
end;
{$ENDIF}
推荐答案
您可以使用Stream:
{$IFDEF MSWINDOWS}
type
TVclBitmap = Vcl.Graphics.TBitmap;
procedure TakeScreenshot(Dest: TBitmap);
var
DC: HDC;
Size: TPointF;
VCLBitmap: TVclBitmap;
Y: Integer;
MS: TMemoryStream;
begin
MS := TMemoryStream.Create;
VCLBitmap := nil;
// Size := FMX.Platform.IFMXScreenService.GetScreenSize;
DC := GetDC(0);
Size.X := 500;
Size.Y := 500;
try
VCLBitmap := TVclBitmap.Create;
VCLBitmap.PixelFormat := pf32bit;
VCLBitmap.SetSize(Trunc(Size.X), Trunc(Size.Y));
BitBlt(VCLBitmap.Canvas.Handle, 0, 0, VCLBitmap.Width, VCLBitmap.Height, DC,
0, 0, SRCCOPY);
Dest.SetSize(VCLBitmap.Width, VCLBitmap.Height);
{ The format of a FMX bitmap and a 32 bit VCL bitmap is the same, so just
copy the scanlines. - not true- FMX bitmap does not have ScanLine? }
VCLBitmap.SaveToStream(MS);
MS.Position := 0;
Dest.LoadFromStream(MS);
MS.Free;
{ Dest.Canvas.DrawBitmap(); Not possible to assign or draw }
finally
ReleaseDC(0, DC);
VCLBitmap.Free;
end;
end;
{$ENDIF}
这篇关于VCL.Bitmap到FMX.Bitmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文