Silverlight 3 Quick Tip #1: How to use WritableBitmap - DevCorner

Silverlight 3 Quick Tip #1: How to use WritableBitmap

eWith this post I’m starting the series of Quick Tips post, this time for Silverlight 3.

Today I’ll show how to use WritableBitmap class to paint with content of any Visual element. Let’s start – I created very simple UI with UserControl inside a stack panels and bunch of buttons to control my sample logic

image

By pressing “Paint control” button I’d like to fill the image in  the cell with “Control Image” caption with the picture of the control from the content control in the cell with “Control Instance”. The code is actually very simple:

WriteableBitmap bitmap = new WriteableBitmap(350, 150, PixelFormats.Pbgra32);
bitmap.Render(contentPlaceholder.Content as UIElement, (contentPlaceholder.Content as UIElement).RenderTransform);
 
BitmapSource source = bitmap;
imgControlDrawing.Source = source;

image image

 

Sources as usual – attached here.

 

Stay tuned to more tips and enjoy,

Alex

Published Thursday, March 19, 2009 1:07 AM by Alex Golesh

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: