Windows 8 Metro App - Render PNGs - c#

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.

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

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.

Related

Blur Effect : Silverlight Windows Phone 8.1

I am writing windows phone 8.1 silverlight app,
I have a Stackpanel in my XAML page, I want to create its background "Blur".
Is there any way to do it?
There is no easy way to apply effects such as blur to elements. More typical would be to dim them by placing a partially transparent rectangle over the disabled element.
If you really want blur you would need to render the element to a bitmap, but the bitmap contents, and then place that image over the original element.
If you have an image as background you could add the blurred effect by modifying the image before setting it as background.
There's multiple libraries that allow you do to this eg. Win2D and Lumia Imaging SDK 2.0.
They are both fairly simple to work with and have pro's and con's.
Nokia Imaging SDK allows you to work directly with bitmaps / writeablebitmaps while Win2D has a more smooth blur rendering.
Here's a guide to how you can implement and work with both: http://www.blendrocks.com/code-blend/2015/1/29/implementing-image-blur-in-a-windows-universal-app

Render an image in SurfaceImageSource with direct2D

I'm making a Windows Store Application that display really big images in a ScrollViewer.
The source image is very big and the rendering with the Image is bad (because the Image is really smaller than the source image, so the scaling make the result ugly).
I want to use direct2D to have a better rendering (the project is in c#).
I'm really new to this, so I don't really know how to do... I've found those links that seems interesting:
XAML SurfaceImageSource DirectX interop sample (Windows 8.1)
How to Draw a BitmapSource Using Direct2D
The SurfaceImageSource sample is good, but only shows how to render sharpes...
And I don't know how to use the second links with SurfaceImageSource.
Is there anybody who have a good example about this? Thanks!
I think you can try VirtualSurfaceImageSource.It can render large image.
Learn more:
http://msdn.microsoft.com/en-us/library/windows/apps/hh825871.aspx

Canvas to image in WinRT Code

In Win8 Metro apps i have a canvas it contains images and blocks and i want to save it to be displayed as an image using async, any idea with code?
Can't be done I'm afraid - WinRT has no way to save xaml to an image.
Your best bet would be to handcraft your own bitmap, but it's a lot of work.
Sorry, I could have done with this functionality to!

how to save Canvas as image in WINRT using c# [duplicate]

I am developing a paint like application in metro style with C#/XAML. I want to save whatever content is drawn on canvas as image. I have checked this solutions but it didn't helped me.
Save canvas to bitmap
http://blogs.msdn.com/b/saveenr/archive/2008/09/18/wpf-xaml-saving-a-window-or-canvas-as-a-png-bitmap.aspx
So how can I save the canvas content as image ? Please help me with sample coding.
The accepted answer from Sascha is no longer true for Windows 8.1. There is a new RenderTargetBitmap class that allows Rendered XAML to be converted to a bitmap.
See: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.imaging.rendertargetbitmap.aspx
However I can't seem to render that XAML is Collapsed or otherwise not currently on screen. Any help with that would be appreciated!
It seems it is currently not supported out of the box like we were used to do it with WPF:
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/dd66c749-efed-4b55-a716-e0aa3a637d28
While when doing HTML5/Javascript Metro apps you can do this:
http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/cf8c17dc-68d4-4777-951f-bb7f0665bd06
The standard approach in other xaml frameworks such as Silverlight and WP7 was to use WriteableBitmap, however the version in WinRT doesn't have a constructor that takes a xaml element which leads me to believe that it's currently impossible against the latest API.
Sorry I couldn't be more help/
One workaround is to use Direct2D with DirectWrite. It is a bit involved, but I might make a library available at some point.

Silverlight: Create image from silverlight controls

Is it possible to generate an image from a silverlight control so that the control would render itself and its contents to an image so that I can do sime pixel manipulation on the image?
There is no way to achieve this in Silverlight 2. I have seen people work around this limitation by posting XAML to a server which would use WPF to render it to a bitmap (using RenderTargetBitmap) and return an image.
However, the just released Silverlight 3 Beta includes a WritableBitmap class which can be used to render a Silverlight UIElement into pixels. In the beta there is however a limitation; once you render an element into the bitmap you cannot access its pixels. This restriction should be eased somewhat in the final release.
Silverlight 3 Beta also includes pixel shaders, so you can write a custom shader in HLSL and apply it to any UIElement - this might be the best solution for you. This tutorial video should get you started on writing and using pixel shaders in Silverlight 3 Beta. http://silverlight.net/learn/learnvideo.aspx?video=187303
After searching the Silverlight forums, it seems that this feature isn't available yet, despite many requests. Although, Silverlight 3 beta was just released this week and I'm not sure what the status is on this issue in regards to that release.
http://silverlight.net/forums/p/12240/39427.aspx
http://silverlight.net/forums/t/17109.aspx
http://silverlight.net/forums/p/18438/62854.aspx

Categories