Drawing on FMX canvas with WinApi functions

不羁岁月 提交于 2019-12-06 02:09:42

Based on this answer you simply can't do that.

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!