简体   繁体   中英

How can I use GDI+ in WPF?

I have problems when using GDI+ in WPF. It's was okay in WindowsForm. But in WPF I can't create a graphic object follow this guide , there is no a Graphics class. The controls in WPF also don't have CreateGraphics method. What should I do?

WPF is not based on GDI+, and doesn't use the Graphics class and similar at all. In general, if you're doing drawing in WPF, you'd use completely different techniques.

That being said, WPF can interop with other desktop technologies, like GDI+, though it's typically less ideal to go this route.

The easiest way to do this would be to use WindowsFormsHost to host Windows Forms content, including the GDI+ information, into your WPF application. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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