Graphics library for .net, mono and silverlight - c#

I have a C# application which renders 2D graphics into bitmaps using System.Drawing.Graphics.
I now want to port this application to work on normal .net on windows, mono on linux and in Silverlight/Moonlight.
But at least Silverlight is lacking System.Drawing. Since I don't want to maintain several copies of my rendering code I need one cross platform graphics library.
I see a few alternatives to achieve that:
Use a library available on all platforms
Use a port of System.Drawing to silverlight
Write a wrapper around the graphics libraries of the different platforms myself
I'm trying to avoid 3) due to the required work.
So does anybody know a free library for 1) or 2)? Library should have a reasonable license, i.e. free and not GPL (LGPL is fine).

There is no common library that does the sort of things that System.Drawing does.
This would be a massive undertaking for very little payback.
Of these options this is the only one that is viable.
I'm not sure what sort of graphics you are doing but have you considered XNA? I don't know about its Mono credentials but via Silversprite you might be able to build stuff that compiles for both .NET and Silverlight.

Related

Is it possible to write common graphics code to render visualizations on different platforms (Windows 7 and above/Android/IOS/ Windows mobile)?

We have a custom built data visualization control to draw charts. It was developed using win GDI APIs and the application is built using C++ COM/ATL.
Now we have a requirement to port this module to C# .NET (for maintainability).
The requirement is that the ported .NET control should work in Windows 7 and above (preferably Vista also). The straight forward approach is to start porting the code and replace the C win GDI APIs with .NET GDI+ APIs.
However one additional requirement is to investigate the possibility of reusing the newly written C# .NET code and deploy the same as apps in IOS/Android/Windows mobile (cross platform). I have come across Xamarin, but it looks like I cannot reuse the C# .NET code containing win GDI+ APIs directly.
Q1) Is it possible to reuse the ported GDI+ C# .NET code for developing mobile apps (may be using Xamarin)
Q2) If the answer for above is No, and we chose to start developing the control from scratch(in contrast to porting), What are the alternative approaches? i.e. what rendering libraries can we use?
Suggestions regarding existing visualization libraries which can be used in Xamarin, so that the developed app will work on all platforms are also welcome. The catch is the library needs to provide flexibility for us to add custom interactions to the visualizations.
Thanks!

Does C# natively use GPU for graphics?

I'd like to draw heavy usage graphics in the fastest way. If I use standard C# graphics callbacks (es.graphics.drawline) am I doing it right? Or am I to use different libraries?
Graphics.DrawLine is a GDI+ call. If you're using Windows Forms and doing your drawing with the System.Drawing classes, you're using GDI+, which is not hardware-accelerated. To get hardware acceleration, you need to use WPF in place of WinForms or draw with Direct3D/Direct2D. The latter two (Direct3D/Direct2D) are COM-based, so you'll need a .NET wrapper. Microsoft wrapped Direct3D for .NET with Managed DirectX followed by XNA. Both (I believe) are now deprecated. There are also third-party wrappers for the DirectX libraries that are more up-to-date.
Edit: I just learned from #HansPassant's comment that GDI+ is 2D accelerated. I thought that only applied to GDI (as opposed to GDI+) because GDI+ handles things like antialiasing that (as I understood it) 2D hardware didn't do. But apparently I was wrong.

C# DirectShow / Direct X

My C# application uses DirectShow and requires DirectX to run. I would like check that DirectX is enabled at start-up, can anyone advise the correct method to do so?
Thanks
DirectShow is not a part of DirectX. There is only some intersection in video renderer using DirectDraw and Direct3D, and wrappers over audio APIs which are in fact no longer independent but wrappers over other APIs. I would say there is nothing to check for and DirectShow is already an OS core component, but if you have some specific concerns then what are they? Maybe you could attempt to create some DirectX object directly on app startup and see if this attempt is successful.
I think I'm right in saying if the DirectX DLLs aren't installed on the host machine, your application wont even start. Beyond that, you should always be checking that creation of DirectX objects succeeds before attempting to use them.

C# Charting Library

I've been looking for a good cross-platform charting library to use on a .NET project intended to be run on both Windows and Linux, but everything looks to have a dependency on WinForms controls, seemingly including ZedGraph (not to mention that ZedGraph looks a bit, well, dated).
Microsoft's Chart Controls for WinForms/ASP.NET look great, but like I said, have a dependency on WinForms controls. I know Mono includes WinForms support for Linux, but I'd rather not have to have Linux end-users install WinForms for what's going to end up being a GTK# application.
Does anyone know of any .NET charting library out there that don't depend on WinForms and that has good visual appeal?
P.S. As an example of a nice visual style, on a different PHP-based project, we use pChart (which I would link, but I don't have enough rep for it).
P.P.S. I've thought about using the Google Chart API, but I don't want to require a network connection just to generate charts.
They require Windows.Forms, since GDI (graphics) functions reside in that particular library. Any other chart control will have to use either 3rd party library or provide its own graphics toolkit.
The best thing I could find is Apache FOP:
http://xmlgraphics.apache.org/fop/
You should be able to run it from command line, or integrate it using IKVM.
Finally, why don't you want Windows.Forms library? As far as I know, mono provides a sufficiently working one.

Embed non-managed directX into C# form

I got a quick question about running a directX application (C++) in a managed environment. I'm attempting to write a MDI tool (in C#) where the background of the parent window would be an embedded render window of directX (C++).
I've read ways that involved writing the C++ into a native dll, however it would be prefered to be able to have the C++ projects included within the solution (I dont even know if that's possible though). Eitherway, if you know of some helpful steps, hints, or if this is a bad idea in general, please let me know. Thanks!
The easiest way to do this would be to add a C++/CLI project to your solution. This would then enable you to use the DirectX COM interfaces directly and create a managed wrapper that's easy to call from your C# code. I've taken this approach a few times and it's by far the easiest way of mixing DirectX and .Net that I've ever tried. Managed DirectX used to be an option, but it's no longer supported and it was a fairly small subset of the full COM API anyway.
First of all writing the C++ part in a different dll file doesn't mean that it couldn't be at the same solution as the C# project.
In order to use native DX to render on a managed window you need to pass the HWND window id (use form.WindowId.ToInt32) to the C++ D3Ddevice c'tor. after that each time you'll render using that device it would render on the .NET window.
To do this you probably need two saparate projects - a C++ dll & .NET project. use COM wrapper or p-invoke to pass the HWND to the C++ dll.
If you don't want to spend too much time on writing C++ code for DirectX, you can consider using
SlimDX, since Managed DirectX 1.0 is out of the question, where as 2.0 never leaves the beta and later replace with XNA which has quite different from DirectX itself, and require you to install XNA Game Studio
SlimDX is the opensource version of managed directx with slightly different API and internal structure, but it's easy to use. The recently released version is very stable. I'm currently using it to write a production application.
SlimDX
Managed DirectX

Categories

Resources