Writing text on a WriteableBitmap - wpf

I have searched around and found that most of the answers convert a WriteableBitmap to a System.Drawing.Bitmap. I am currently thinking of using WriteableBitmapEx's Blitz() function to overlay a bitmap with text onto the existing bitmap, but I don't really find functions that return WriteableBitmap.
Is there a easy way to draw text?

I managed to use the WriteableBitmapEx DrawString() method to achieve this directly.
Unfortunately it is not inside the Nuget Packages so it has to be compiled from the source of another project:
https://writeablebitmapex.codeplex.com/discussions/579148
https://fastwpfgrid.codeplex.com/SourceControl/latest#WriteableBitmapEx/LetterGlyphTool.cs

Related

WriteableBitmap used in Mat.Mat constructor (Emgu.CV)

what I'm trying to do is using an let say pre-loaded image within Emgu.CV.Mat. It offers an constructor where its possible to specify a filename. But my image is already loaded (and manipulated) within the code, therefore it makes no sense to save the file here just to load it again.
I'm working within a WPF Environment and therefor have my image currently as a WriteableBitmap. Furthermore I found couple of hints (e.g. here) how to convert an Mat to WriteableBitmap. But what I'm looking for is the other way round, using a WriteableBitmap in order to Emgu.CV stuff with it.
According to Emgu CV 2.x it was possible to use a Bitmap but it seams that this feature was removed in Emgu CV 3.x.
Any ideas how to do it in Emgu CV Version 3?
I have been experimenting in this area for a work related application. To effectively use a WriteableBitmap with a Mat or an Image<,> you need access to the raw pixels.
Because I have images coming from hardware as well as from creating a RenderTargetBitmap what I found works for me is to allocate a buffer using HGlobalAlloc that is the proper size and use RenderTargetBitmap.CopyPixels() to move the data to this buffer. I also create an Image using an IntPtr to this data. Once I am done with my manipulations I use a WiteableBitmap.WritePixels() to put the image back into the WriteableBitmap.
Here is also a solution from Emgu: BitmapSourceConverter
Doug

Silverlight: convert UIElement to SVG

I am looking for the best way of converting a UIElement(FrameworkElement) to vector format (vector analog for WritableBitmap).
The easiest way that comes to mind is manually create special SVG converter for some of UIElement implementations and try to get full vector image.
Generally it will be used for converting Canvases with Shapes.
Any ideas how to do this best way?
Check out http://sanpaku72.blogspot.com/2007/09/having-fun-with-xaml-silverlight-and.html
It has a link to http://members.chello.nl/~a.degreef/xaml/xaml2svg.xsl and download the other xsl files by following the includes, like http://members.chello.nl/~a.degreef/xaml/xaml2svg/animation.xsl

Saving xlib XImage to PNG

I am using xlib.
I have an XImage structure filled with information from an XGetImage() call. Is there a popular method to get from XImage to something more meaningful.. namely PNG?
I have looked at libpng, but have heard from pretty much everyone that it's a beast to tame. Would this still be the recommended path to take?
See also How to save XImage as bitmap? though that person had the constraint that they couldn't use a library.
If you can use a library, Cairo is a good one that will do this for you I believe. It has PNG saving dealing with the libpng mess for you, and it has code to get the pixels from X. However, it may make it hard to get pixels from an XImage; it will want to get them from a window or pixmap. If you can just replace your XGetImage() with cairo, then it might work fine. The way you would do things roughly in cairo I think is:
create an Xlib surface pointed at your drawable
save to PNG http://cairographics.org/manual/cairo-PNG-Support.html
You could also use the Xlib surface as source to draw to an image surface, and then do other stuff with the image surface (scale or paint on it or whatever) if you wanted, before saving as PNG.
If you're using any kind of UI toolkit, it probably has code for this too, e.g. GTK+ has gdk_pixbuf_get_from_drawable() etc.

Working with bitmap in WPF

Is there any sane way to work with bitmaps in WPF? I'd like similar functionality as System.Drawing.Bitmap: be able to load image from file and get and set the color of particular pixels.
I know about WriteableBitmap, but I don't want to work with Arrays of gods-know-what (I couldn't find that on MSDN), or pointers. I just want to read or write pixel, it shouldn't be that hard!
I also know that I can use Interop to work with System.Drawing.Bitmap in WPF, but that's not nice either.
Here's something on how to do get pixel info from a System.Windows.Media.Imaging.BitmapImage.
Although, if you'd prefer to work with a System.Drawing.Bitmap you might want to add a reference to System.Drawing.dll and use it instead.
Here's a somewhat-related forum post on image manipulation in WPF.

Convert an image to XAML?

Does anyone know of any way to convert a simple gif to xaml? E.G. A tool that would look at an image and create elipses, rectangles and paths based upon a gif / jpg / bitmap?
Inkscape can trace bitmaps, and can save directly to XAML. And, it happens to be free. I've used it to trace a lot of bitmaps and it's worked really well for me.
Illustrator has a trace tool which will do this
a cheaper option might be
http://vectormagic.com
it will export a svg that you should be able to convert to xaml
A combination of Vector Magic followed by ViewerSVG produces the best quality results for me.
With this online converter you can convert an image to SVG Format. then download Converted File and open it in a text File Editor then you can easily copy path data
image.online-convert

Resources