Link to home
Start Free TrialLog in
Avatar of debrunson
debrunson

asked on

Can I use Direct2D with C#?

In the past I have successfully created a C++/MFC program which utilizes Direct2D functionality (ID2D1Factory, ID2D1HwndRenderTarget, ID2D1Bitmap, etc) to load, save, and convert image formats.  However now I am writing a C#/.NET program which must do all of these same things.  I am very new to C#, but I have not been able to find any references to C# being used with Direct2D.  Can someone clarify their relationship for me?
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Moving to .NET while using older technologies is not the way to go. The use of pointers is very limited in C#, so dealing with older stuff requires an extra layer between C# and the old stuff. This might be OK for simple stuff, but for things that can more extensive manipulations, this is not the way to go.

.NET come with a few classes that provides simple manipulations and conversion for image and image files. Look for the Image and Bitmap class in the documentation.

If you need more complex types of manipulations, such as drawing and background painting, you can use the classes from the GDI+ Library, available through the System.Drawing namespace. The link is an old but still valid and good introduction to the technology built into the .NET framework for graphic manipulations.

If your needs are closer to what is used in games, go for a little search for Microsoft XNA.
Avatar of debrunson
debrunson

ASKER

Thank you very much.  I will look at the Image and Bitmap classes in C#.  However, let me ask this - my program accepts images from a video camera so there is a lot of data being transferred fairly rapidly.  In my earlier C++ program, I originally used GDI+ to display the images but moved away from it because it was too slow.  Moving to Direct2D was much better and performance improved greatly.  It is my understanding that Direct2D uses the graphics card for image processing rather than just the CPU.

Might I expect a downgrade in performance when moving from C++/Direct2D to C#/GDI+?

Thanks
Yes.

C# and GDI were not designed to handle low level stuff such hardware drivers and graphic cards.

Because C++ uses pointer, it will aways offer a better performance than C#.

You might give a look at XNA however. It was created because GDI was not fast enough for games. I have not used it personnally because I am not into game development, but it might offer you something in between.

Otherwise, because you are processing images at such a speed, I think that sticking to C++ would be a better bet.
One more question if you would be so kind.  I have been told that MFC is coming to an end and that the way forward is C# with .NET.  If that is true there must be some Microsoft-supported way to handle image processing with some degree of speed, no?
Avatar of David Johnson, CD
you can create a hybrid project that has both .net and c++ dll's
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks to both of you.  I of course have no authoritative source indicating the demise of MFC but I thought that Windows 10 and the rise of touch screens/tablets were the reason that Microsoft was ramping up C#/.NET.  I have heard from other programmers and blogs online that C# is the way of the future and C++ should be used only for legacy projects.

If C# has no good way to handle the (relatively simple) image processing that I require, then I will either stick with C++ or use the DLL approach.

Many thanks.
Windows 10 is still Windows. Although it supports touch and can run apps, it's main use on a desktop is still to run Office, games, business applications. The fact that they came back to a more standard environment after Windows 8 shows that it is still needed as is. If you think that tablets will replace the desktop, go and ask anybody who tried to work in Excel or Word on a tablet how they found their experience.

.NET (no matter the language) is definitively the way to go for most business applications.

C# is definitively the way to go if you think mobile, because it attracts programmers from other platforms and is supported on other platforms. It's similarity to JavaScript also makes it the most evident choice for web development.

But that does not automatically "kill" C++, that still has its place for applications that need to work close to the OS or peripherals. Same thing for anything that requires lots of number crunching operations. The big games are still coded in C++, there is a reason for that.

Hey! I know programmers who still do a lot of assembler for some types of work because even C++ is too slow for them.

Each language and each library has its place.
I totally agree with you about the use of tablets, and that C++ will surely be around for a good long time to come.  Tablets are great for many things but a desktop/laptop-type environment will not be replaced for many heavy-duty business applications.  However, our project involves developing a product for image viewing and processing on a mobile platform, so I was trying to figure out which direction to go.  I am very familiar with C++/MFC but was not sure it is the best thing to use for our new product.  It could well be more desirable to run it on a tablet for the sake of portability.