Vector Graphics in C# WinForms - should I interoperate with WPF? - c#

I have a video camera that I'm interfacing with a C# app. The camera actually comes with a .NET WinForms control. It supports drawing on it with GDI+ functions.
When I zoom in, I need <1 pixel accuracy i.e. I want to draw a circle with a radius of less than two pixels. How can I draw vector graphics in WinForms? Is my best bet to overlay a WPF Canvas? I know I can use WPF controls in WinForm apps, but is it possible to make the background of a ElementHost/WPF canvas transparent and overlay it onto my video feed? Am I better off creating a WPF app, and only using this video control on the WindowsFormsHost provider?
Any other solutions of drawing vector graphics in C# apps?
Thanks in advance.

Well, unfortunately you won't be able to use WPF to overlay anything on your WinForms control due to airspace issues. Winforms and WPF content is not allowed to overlap inside the same window. You're stuck using vanilla GDI or another custom Winforms vector library.
MSDN Link to explanation of interoperability issues.

Related

How to draw 10000+ ellipses on WPF canvas?

I'm writing a app to built a CAD viewer.
When I using EllipseGeometry in canvas, it's very slow to create/move graphics.
So i change to use DrawVisual. it's faster than using EllipseGeometry, but still very slow to move the whole graphics.
is there any sample code to show me how to deal with so many ellipses.
I think it's probabily too much for WPF.
I would go for DirectX. See SharpDX which is no longer mantained but will give you an idea.
See also Fast 2D graphics in WPF

Display WPF controls over OpenGL window in Windows desktop application

We're developing Windows desktop app with full-screen OpenGL graphics. Now we want to display a bunch of controls over the OpenGL (arrows, buttons, etc.) It turns out it is very difficult to do that.
The majority of tutorials suggest using WindowsFormsHost for OpenGL rendering, and we did so: http://www.codeproject.com/Articles/23736/Creating-OpenGL-Windows-in-WPF
Unfortunately now we cannot draw WPF controls over WindowsFormsHost, there's a lot of discussion about this all over the internet too: WindowsFormsHost is always the most top from WPF element
Render WPF control on top of WindowsFormsHost
There are some hacks that can work around this, but they all seem very dirty.
Is there a proper way to draw OpenGL directly in WPF without messing with Windows Forms? (I just have no idea why you cannot have this in WPF directly).
In short: is there a known solution for drawing UI over OpenGL in WPF applications?
Create a wpf window.
Render your opengl viewport in background.
Get the Snapshot of the opengl viewport and display the image in the WPF.
Transfer all UI Events on the WPF Image to the opengl viewport.
EDIT:
There is a way to host win32 window inside WPF window.
You can refer this video https://www.youtube.com/watch?v=JO4uW8Xb230.
If you are using GLFW for creating win32 window, you just need to use the underlying handle or just cast the window to HWND that WPF needs to host the window.

How to make a nice overlay with variable transparency using WinForms?

I'm looking for a way to make a WinForm transparent and allow to use semi-transparent images on it.
The common solutions are:
Changing the total opacity of the form and all of its content;
Make only a certain color fully transparent, while the rest will have to be fully opaque;
Use multiple forms to make only some controls transparent.
None of these ways allow to display images or controls which have variable per-pixel transparency value. And I'd like to achieve a cool interface like Steam does with its in-game overlay.
Is there maybe some video game technique that can be used to draw a nice overlay for the whole screen? It's okay if it will have to use 3D graphics drawing libraries and whatnot.

What is the equivalent to Java's canvas object in C#?

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).

16 bit grayscale image display in WPF

I am developing an application that displays 16 bit grayscale images. The UI for the application was originally created using Win Forms and since Win Forms does not support 16 bit grayscale I wrote a custom openGL control to display the image. Within the last few months we have convert the UI to WPF, but continued to use the openGL image display via a WindowsFormsHost.
WPF is DirectX based so it would make sense to try and get away from the openGL, but does WPF natively support 16 bit grayscale images? or will I have to create a DirectX control?
Also, the openGL control isn't only used to display the image data. The contol allows the user to manipulate the image in various ways (Flip, rotate, Zoom, pan, crop, etc); as well as annotate the image (draw lines, rectangles, measurement angles, etc). If I'm simply using WPF to display the image, how can I also manipulate and annotate using WPF? Plus, I am using a shader to do some color mapping on the image texture. Is something like this possible with WPF or will I have to color map the image data manually before displaying?
I have never used DirectX, so if writing a DirectX control is necessary how difficult will it be to learn and implement what I need?
As for the shaders parts, WPF have access to the HW shaders (and it can emulated them in SW if needed) they are called bitmap effects.
Greg Schechter's covered how to write a custom effect in his blog

Categories

Resources