[英]How to deal with printing in a mixed-mode project?
I have a mixed-mode project C#(WPF) -> C++/Cli -> unmanaged C++. 我有一个混合模式项目C#(WPF)-> C ++ / Cli->非托管C ++。
The graphics is dealt with in c++. 图形用c ++处理。 Some things are drawn and then transferred to c# thru a c++/cli interface object. 绘制一些东西,然后通过c ++ / cli接口对象将其转移到c#。 In c# this interface is put on a xaml form and shown. 在C#中,此接口以xaml形式显示。
Now I need to send this picture to a printpreview and then to a printer. 现在,我需要将此图片发送到打印预览,然后再发送到打印机。
How can it possibly be done? 怎么可能呢?
I thought about serializing, but couldn't find anything about serializing c++/cli interfaces. 我考虑过序列化,但是找不到有关序列化c ++ / cli接口的任何信息。
Any ideas? 有任何想法吗? Thanks! 谢谢!
EDIT Ok, so I have to explain further on. 编辑好的,所以我必须进一步解释。
In my c# project I have a c++/cli object, through which I can communicate to my graphics in c++, and this object has many methods, like f.ex: 在我的c#项目中,我有一个c ++ / cli对象,通过它可以与c ++中的图形进行通信,并且该对象有很多方法,例如f.ex:
object.DrawLine
object.DrawSmthElse
object.UpdateImage
etc. etc. 等等等
So, when in WPF I show a xaml form, the filling of this form is happening through this object, like I call all these methods to draw all the things I need. 因此,当在WPF中显示xaml表单时,该表单的填充正在通过该对象进行,就像我调用所有这些方法来绘制所需的所有东西一样。
Now the question is: I need to send to printer exactly this graphics part (which is done in c++). 现在的问题是:我需要把这个图形部分准确地发送到打印机(在c ++中完成)。 In what form should I do it? 我应该以什么形式来做? How can I pass this object to a DocumentViewer in c# for example? 例如,如何将该对象传递给c#中的DocumentViewer?
I hope that would be enough to put the question off hold. 我希望这足以解决这个问题。
Try sending the raw bytes of the bitmap to/from managed code and unmanaged code. 尝试向托管代码和非托管代码发送位图的原始字节。
On the managed side, you can create a bitmap object with a Stream . 在托管方面,您可以使用Stream创建一个位图对象。 You can also save an existing bitmap out to a stream . 您还可以将现有位图保存到流中 。 You can use a MemoryStream to easily read and write bytes to/from managed and unmanaged code within your C++/CLI objects. 您可以使用MemoryStream轻松地在C ++ / CLI对象中的托管代码和非托管代码中读写字节。
-- -
If the image is already on the Managed side (i couldn't tell if it is or not), then you can use the PrintPreviewDialog and PrintDialog ( example ) 如果该图像已经在Managed一侧(我无法确定它是否存在),则可以使用PrintPreviewDialog和PrintDialog( 示例 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.