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?
debrunsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
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.
0
debrunsonAuthor Commented:
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
0
Jacques Bourgeois (James Burger)PresidentCommented:
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

debrunsonAuthor Commented:
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?
0
David Johnson, CD, MVPOwnerCommented:
you can create a hybrid project that has both .net and c++ dll's
0
Jacques Bourgeois (James Burger)PresidentCommented:
Where did you hear that MFC is coming to an end? This is propagated lore such as VB is coming to an end.

True, C# is at the forefront of Microsoft marketing strategy for now, in part because it attracts programmers from other platforms with it's multi-platform features.

But as long as Windows will be there, and I do not see a Windows .NET in the future, MFC will still be there. There are so many applications running on that library that you can be sure that although they push on C# for new development, MFC is there to stay for a long while.

This being said, David is right. You can create a user interface in C# with C++ dll's that do the hard work in the background.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
debrunsonAuthor Commented:
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.
0
Jacques Bourgeois (James Burger)PresidentCommented:
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.
0
debrunsonAuthor Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.