使用WinApi功能在FMX画布上绘图 [英] Drawing on FMX canvas with WinApi functions
问题描述
这个问题看起来很简单,使用VCL可以很好地工作(图像是VCL上的TImage):
This question looks very simple, with VCL this is works fine (Image is TImage on VCL):
procedure TFormMain.btnDrawBackgroundClick(Sender: TObject);
var
theme: HTHEME;
begin
theme := OpenThemeData(0, 'TASKDIALOG');
if theme <> 0 then
try
DrawThemeBackground(theme,
Image.Canvas.Handle,
TDLG_SECONDARYPANEL,
0,
Image.ClientRect,
nil);
finally
CloseThemeData(theme);
end;
end;
问题:为了在FMX上获得相同的效果(在Windows上),我应该改变什么
Question: what I should change to get the same effect with FMX (on Windows)
推荐答案
基于此答案根本无法做到这一点。
Based on this answer you simply can't do that.
问题在于,使用Firemonkey,您只有一个设备
表单上下文而不是每个组件一个。当需要重新绘制组件
时,它会通过表格画布,但会剪切
并将坐标映射到组件位置。
The problem is that with Firemonkey, you only have a single device context for the form and not one for each component. When a component needs to be redrawn, it gets passed the forms canvas but with clipping and co-ordinates mapped to the components location.
但是总有一些解决方法,您可以尝试这样。
But there is always some workaround and you can try something like this.
procedure TFormMain.btnDrawBackgroundClick(Sender: TObject);
var
lTheme : HTHEME;
lStream : TMemoryStream;
lBitmap : Vcl.Graphics.TBitmap;
begin
lTheme := OpenThemeData(0, 'TASKDIALOG');
if lTheme <> 0 then
try
lBitmap := Vcl.Graphics.TBitmap.Create;
try
lBitmap.Width := Round(Image.Width);
lBitmap.Height := Round(Image.Height);
DrawThemeBackground(lTheme, lBitmap.Canvas.Handle, TDLG_SECONDARYPANEL, 0,
Rect(0, 0, lBitmap.Width, lBitmap.Height), nil);
lStream := TMemoryStream.Create;
try
lBitmap.SaveToStream(lStream);
Image.Bitmap.LoadFromStream(lStream);
finally
lStream.Free;
end;
finally
lBitmap.Free;
end;
finally
CloseThemeData(lTheme);
end;
end;
这篇关于使用WinApi功能在FMX画布上绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!