Can I combine code that uses System.Drawing.Bitmap together with other code in a program that uses GTK#?
I would like to be able to display the Bitmap image processed in a GTK# window/widget.
More generally, is there any interoperability between the two toolkits?
For example is there any classes, like Rectangle, that would work on both, or perhaps a wrapper class?
System.Drawing isn't really specific to WinForms, and it's at the very least possible to get Graphics instances from Gdk.Drawables in Gtk#.
Related
I'd like to implement my own control for Windows Phone. The catch is, that I want to draw it myself - in regular WPF I'd simply override OnRender method and provide my own implementation. However, there is no OnRender method available on Windows Phone. What other options do I have?
What is not acceptable in my case is:
Drawing on bitmap in background and displaying it
Using vector shapes instead of raster drawing
Since Windows.UI.Xaml doesn't have a raster graphics API the only options are to use vector graphics, to render into a bitmap and display that, or to interop to DirectX.
Microsoft's Win2D library at http://microsoft.github.io/Win2D (also see http://blogs.msdn.com/b/win2d/ ) exposes Direct2D through C# and is probably the best match for what you are looking for. It is a work in progress and provides most basic features, but if you need more you'll need to do the interop yourself.
The closest other option is to use a 3rd party library such as WriteableBitmapEx for a high level API to draw into a WriteableBitmap. You could extract the generated bitmap into an ImageBrush for display without an explicit Image control.
I am trying to develop a Windows Store App that generates and saves bitmap images which are composed of various images, primitive shapes and text. I don't necessarily want all the images to be on screen as there might be a lot of them which I need to generate. My app is written in C#. I see that Microsoft introduced a new RenderTargetBitmap class in Windows 8.1--which I am planning to target--but it only saves XAML trees that are on screen. Is my only choice to go with C++? If so what C++ library is free, compatible with WinRT and has a simple API?
Take a look at WriteableBitmap. It allows you to draw pixels manually in an image, by first writing them out to a byte array.
If you need additional tools for rendering shapes and the like, WriteableBitmapEx can be a good option. To quote from the link:
The WriteableBitmap API is very minimalistic and there's only the raw
Pixels array for such operations. The WriteableBitmapEx library tries
to compensate that with extensions methods that are easy to use like
built in methods and offer GDI+ like functionality. The library
extends the WriteableBitmap class with elementary and fast (2D
drawing) functionality, conversion methods and functions to combine
(blit) WriteableBitmaps.
As part of my audio libary i would like to create a sample visualisations.
I know how I get the values I want to draw like fft results and so on.
But the main problem is that I don t know whats the best way to draw them. I have quite a lot of experience in using wpf but I never had to do something like this. What should I use to keep performance as good as possible?
There are a number of different approaches you can take, depending on the quality you need, memory usage, and performance....here are just some.
create a new object derived from FrameworkElement, and then inside draw the "visual" aspect dynamically by drawing onto a DrawingContext during OnRender. Drawings have a much lower overhead than other WPF elements such as Shapes, Image, etc. However, it still may not scale well if you have 1000s of elements. http://msdn.microsoft.com/en-us/library/ms751619.aspx
WriteableBitmapEx....it will give you the drawing primitives you need to write into a Bitmap directly. http://writeablebitmapex.codeplex.com/ .. see this for some demos which are spookily similar to what you would do for an audio visualization. http://blogs.claritycon.com/blog/2011/03/advanced-animation-animating-15000-visuals-in-silverlight-2/
use DirectX with Direct2D. This offers DirectX like performance, but you would need to use COM interop or C++/CLI code wrappers to make it available to your .NET C# code. http://www.codeproject.com/Articles/113991/Using-Direct2D-with-WPF
Some other links:
http://jeremiahmorrill.wordpress.com/2011/02/14/a-critical-deep-dive-into-the-wpf-rendering-system/
Can Viewport3D control in WPF work with OpenGL?
The WPF's something Viewport3D can't do (there are lots of thing it can't do), whole WPF is DirectX based. This also means DirectX is generally much better supported in WPF.
However you can use OpenTK's WinForms viewport and use WinFormsHost to put it in your application. OpenTK is a very nice .Net wrapper for OpenGL.
However you will not be able to use XAML, bindings and other WPF-specific stuff. You will have to do the OpenGL calls manually from code. All the interop does is that is places the viewport in your application and lets you do .Net calls on it.
You may also want to have a look at this project.
It cannot, in the sense that you can merge 3D content from OpenGL to Viewport3D seemlessly (with correct Z testing and all).
I'm working on creating a basic application that will let a user draw (using a series of points) and I plan to do something with these points.
If this were Java, I think I would probably use a canvas object and some Java2D calls to draw what I want.
All the tutorials I've read on C#/Drawing involve writing your own paint method and adding it to the paint event for the form. However, I'm interested in having some traditional Form controls as well and I don't want to be drawing over them. So, is there a "Canvas" object where I can constrain what I'm drawing on?
Also, is WinForms a poor choice given this use case? Would WPF have more features that would help enable me to do what I want? Or Silverlight?
A Bitmap will work fine, display it with the PictureBox.Image property. Use Graphics.FromImage() to get the Graphics object you'll need to draw on the bitmap. Use PictureBox.Invalidate() to let the PB know that it needs to update the image on the screen.
Well, there is a control called 'canvas' in WPF which may suite you. If you are using Windows Forms, i think the best choice will be to draw on a panel control. Windows forms are in no way a poor choice. Indeed, when using them you can even develop a cross-platform applications. However, WPF is more 'rich' in some way. I think that if you are not aiming at any other platforms, and you don't have to stick with .NET 2.0 WPF is a preferred choice (especially, if you are going to use some graphics in your application, because WPF uses hardware acceleration).