Where can I find documentation and/or examples of working with TMetafile and TMetafileCanvas?

落爺英雄遲暮 提交于 2019-12-24 10:39:09

问题


As I'm working to add custom printing to my application, I've settled on using TMetafile to create the pages, then using it to preview &/or print, but I'm finding the documentation lacking.

Are there any good resources for learning the ins and outs of working with TMetafile and TMetafileCanvas?


回答1:


The ins and outs of working with TMetaFile/Canvas are more related to meta files than to the TMetaFile and TMetaFileCanvas implementations from my traumatic experience of working with it. Aka, you should rather look for information on how EMF (or WMF) works. The Delphi implementation simply calls windows to do everything as I understand it.

You may wish to be more specific what it is you need to know though beyond a walk through guide on how to do it.




回答2:


It's actually simpler than you think...

here's some of my code:

var
   m: TMetafile;
   mc: TMetafileCanvas;
begin
   m := TMetafile.Create;
   m.Width := 1000;
   m.Height := 1000;
   mc := TMetafileCanvas.Create(m, 0);
   //use mc just like any canvas...
   mc.Free;
   // you can use m for anything you want, preview, print, save ...etc.
end;

To copy the metafile to the clipboard:

Clipboard.Assign(m);

To Save to an emf file:

m.SaveToFile(filename);

I've used that to print a metafile in a fastreport.




回答3:


I haven't looked into it much myself, but I know that the QuickReports code uses metafiles under the hood to create the print preview and to send to the printer. If you've got the source for that, it may be helpful.



来源:https://stackoverflow.com/questions/465911/where-can-i-find-documentation-and-or-examples-of-working-with-tmetafile-and-tme

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