3

I am needing to render some custom PNGs in a Windows 8 app.

Basically I need to create a custom live tile by putting some drawings made in my app on top of an image for a live tile, and the only way to do this is render a PNG to disk, see here.

What library should I use to do this? My first thought was to use a Xaml UserControl and RenderTargetBitmap, but it is not available in a Metro app.

Community
  • 1
  • 1
jonathanpeppers
  • 26,115
  • 21
  • 99
  • 182

2 Answers2

1

Currently the only option is to use DirectX (or SharpDX) to create your image. You'll probably have to recreate the drawing using the low-level DirectX APIs. WritableBitmapEx might also be helpful if your drawings are simple.

robertos
  • 1,810
  • 10
  • 12
  • WriteableBitmapEx look's like it is what I'm looking for. I can see where I can render an image and draw lines on top of it. Are there any examples of saving out to disk? – jonathanpeppers Aug 29 '12 at 15:27
  • I don't have any sample here but you'll want to use this: http://msdn.microsoft.com/en-us/library/windows/apps/windows.graphics.imaging.bitmapencoder.aspx – robertos Aug 30 '12 at 21:44
  • That is what the extensions from the WinRT Xaml Toolkit use. So an example is here for those needing it: http://winrtxamltoolkit.codeplex.com/SourceControl/changeset/view/17730#327690 – jonathanpeppers Aug 30 '12 at 23:27
1

WinRT XAML Toolkit has some extension methods for WriteableBitmap that you could use too. You could probably use WriteableBitmapLoadExtensions for loading and WriteableBitmapSaveExtensions for saving. It has a fairly limited blitting capability though since that is exposed by WriteableBitmapEx already and simple to write anyway. WriteableBitmapBlitBlockExtensions is only a method to blit a full width block of pixels from bitmaps of same width.

Edit* RenderTargetBitmap is now available in Windows 8.1. It doesn't support some elements though (I think it doesn't render camera previews, media elements and perhaps WebViews).

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
  • I actually ended up taking some extensions from there to save out to a PNG file. Are there any extensions to render lines? Or even render other images at angles to create lines? I got my case working with `WriteableBitmapEx` but the lines are very ugly compared to what is rendered in our game. – jonathanpeppers Aug 30 '12 at 12:12
  • I think you would need to either look into Direct2D or implement your own antialiased line drawing methods. – Filip Skakun Aug 30 '12 at 14:45
  • We are using MonoGame, so I will see if `RenderTarget2D` will work. Last I checked `RenderTarget2D` didn't work in MonoGame (on iOS). I will try it for Windows 8. – jonathanpeppers Aug 30 '12 at 14:53