简体   繁体   English

如何在WPF中使用GDI +?

[英]How can I use GDI+ in WPF?

I have problems when using GDI+ in WPF. 在WPF中使用GDI +时遇到问题。 It's was okay in WindowsForm. 它在WindowsForm中没问题。 But in WPF I can't create a graphic object follow this guide , there is no a Graphics class. 但是在WPF中我无法按照本指南创建图形对象,没有Graphics类。 The controls in WPF also don't have CreateGraphics method. WPF中的控件也没有CreateGraphics方法。 What should I do? 我该怎么办?

WPF is not based on GDI+, and doesn't use the Graphics class and similar at all. WPF不是基于GDI +,并且根本不使用Graphics类和类似的。 In general, if you're doing drawing in WPF, you'd use completely different techniques. 一般来说,如果您正在使用WPF进行绘图,那么您将使用完全不同的技术。

That being said, WPF can interop with other desktop technologies, like GDI+, though it's typically less ideal to go this route. 话虽如此,WPF可以与其他桌面技术(如GDI +)互操作,尽管通常不太适合这条路线。

The easiest way to do this would be to use WindowsFormsHost to host Windows Forms content, including the GDI+ information, into your WPF application. 最简单的方法是使用WindowsFormsHost将Windows窗体内容(包括GDI +信息)托管到WPF应用程序中。 You could then use standard Windows Forms controls, which will provide the graphics API you're expecting, and just embed it into a WPF container. 然后,您可以使用标准的Windows窗体控件,它将提供您期望的图形API,并将其嵌入到WPF容器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM