OnRender equivalent in Windows Phone - c#

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.

Related

What is the simplest way to compose a bitmap image in a Windows Store App

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.

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

Windows.Forms and gtk# interoperability?

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

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

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.

Categories

Resources