Oana and Arthur | Our dev blog

PrintScreen in Silverlight

I've wanted to convert rendered XAML content into an image file (PNG is a good start so I chose it for today's post). I took advantage of an open-source, third party library called .NET Image Tools which did a great job encoding PNG files. It can be found @CodePlex, the open-source project hosting space from Microsoft (check it out).

Let's start with the basic idea of this post. You have let's say, a Silverlight Canvas control and you would like to take a snapshot of it, make a print screen but not using external tools yet having it done within your own Silverlight app.

Here's the code:

//Creating a WritableBitmap object in order to use it as the source

//of an Image control

WriteableBitmap writableBitmap = new WriteableBitmap(MyPrintScreenCanvas, null);

BitmapSource bitmapSource = writableBitmap;


//Creating an Image instance which will be encoded later-on

Image image = new Image();

image.Source = bitmapSource;


//Encoding the Image object to a PNG file

//using .NET Image Tools library

ImageTools.IO.Png.PngEncoder pngEncoder =

   new ImageTools.IO.Png.PngEncoder();

MemoryStream ms = new MemoryStream();

ImageTools.Image ITImage = ImageTools.ImageExtensions.ToImage(MyPrintScreenCanvas);

pngEncoder.Encode(ITImage, ms);

Now you have the MemoryStream and you can save it to a file, send it as an email or store it on a server using a WCF or ASMX web service.

Thanks and bye bye, Arthur

Tags: , ,
Categories: .NET | C# | Silverlight
Actions: E-mail | Permalink | Comment RSSRSS comment feed

Visual Studio 2010 Beta 1 out now!

Mult asteptatul beta de la Visual Studio a ajuns sa fie lansat.

Dupa cum va puteti inchipui chiar nu se poate compara versiunea CTP cu versiunea beta de acuma, ultima fiind mult mai stabila si indeosebi rapida (cealalta ruland doar pe o masina virtuala). Astazi am inceput sa dezvolt pe el (vorba vine, sa dezvolt, de fapt sa ma joc cu interfata noua facuta in WPF), va astept si va rog chiar sa faceti si voi acelasi lucru.

Variantele ISO ale VS 2010 Team System sau Professional impreuna cu alte tool-uri micute le gasiti aici:

Visual Studio 2010 Beta 1


© Microsoft

Tags: , , ,
Categories: .NET
Actions: E-mail | Permalink | Comment RSSRSS comment feed