【发布时间】:2016-03-18 06:41:07
【问题描述】:
我创建了一个简单的 FireMonkey 屏幕截图,可以在 Android 和 Windows 上正常运行。..:
procedure Capture;
var
B : TBitmap;
begin
try
B := Layout1.MakeScreenshot;
try
B.SaveToFile( ..somefilepath.png );
finally
B.Free;
end;
except
on E:Exception do
ShowMessage( E.Message );
end;
end;
结束;
当我将它移至如下线程时,它在 Windows 中运行良好,但在 Android 中,我从调用 MakeScreenshot 中得到异常“位图太大”。在线程中使用 MakeScreenshot 是否需要额外的步骤?
procedure ScreenCaptureUsingThread;
begin
TThread.CreateAnonymousThread(
procedure ()
var
B : TBitmap;
begin
try
B := Layout1.MakeScreenshot;
try
B.SaveToFile( '...somefilepath.png' );
finally
B.Free;
end;
except
on E:Exception do
TThread.Synchronize( nil,
procedure ()
begin
ShowMessage( E.Message );
end );
end).Start;
end;
稍后添加。根据 Sir Rufo 和 Sebastian Z 的建议,这解决了问题并允许使用线程:
procedure Capture;
begin
TThread.CreateAnonymousThread(
procedure ()
var
S : string;
B : TBitmap;
begin
try
// Make a file name and path for the screen shot
S := '...SomePathAndFilename.png';
try
// Take the screenshot
TThread.Synchronize( nil,
procedure ()
begin
B := Layout1.MakeScreenshot;
// Show an animation to indicate success
SomeAnimation.Start;
end );
B.SaveToFile( S );
finally
B.Free;
end;
except
on E:Exception do
begin
TThread.Synchronize( nil,
procedure ()
begin
ShowMessage( E.Message );
end );
end;
end;
end).Start;
end;
【问题讨论】:
-
你不应该同时使用Delphi、
TThread和TBitmap(你只会面临错误)......并且你必须在主线程上下文,否则您将只生成一个随机骰子应用程序(可能有效或无效)
标签: android multithreading delphi screenshot firemonkey