Canvas to image in WinRT Code - c#

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!

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

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.

Windows 8 Metro App - Render PNGs

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.

Simple component to crop a picture with rectangle box in c#.net windows application

I want a simple component to crop a picture with Rectangle box in c#.net windows application.what component can i use?(free or purchase)
Here's some code I wrote to resize an image. The code will also trim the image if needed.
It provides an example of cropping and could easily be modified to be a more general "cropper" class.
I used ClearImage for image manipulation at a previous job. I found it very easy to use, with good performance and it would serve your purpose perfectly.
There is also AForge, a open source image manipulation library. A little more powerfull, with a lot of features, but also a little more complicated.
Or you could design your own using the PictureBox and the Bitmap class. A lot of work, and probably not very performant if you don't know what you're doing...

Categories