Skip to main content
Home Forums Silverlight Design Designing with Silverlight Creating images from xaml...
3 replies. Latest Post by ksleung on July 9, 2009.
(0)
Cleon26
Member
392 points
111 Posts
07-08-2009 11:55 AM |
Has anybody attempted to create an image (gif/jpeg/png) from a xaml asset? Most of the icons in our application are xaml (so we could make use of the resizing capabilities) but we need a few of them to be images so we can include them in some reports. I thought that Expression Design would allow me to import xaml and export it as an image but Expression Design does not import xaml... :(
milind.s...
389 points
72 Posts
07-09-2009 12:14 AM |
Even I faced this need few days back. There is no way from the tools but a trick.
Limitation with this trick is, the maximum size of image you can get is less than your screen resolution.
sorskoot
241 points
42 Posts
07-09-2009 3:26 AM |
In silverlight this isn't possible. But, in WPF you can render to a bitmap and save this to disk or return it as an byte array. I assume the xaml assets you're talking about aren't that complicated and silverlight specific and will work in a WPF app.
Last month I use this in a PHP project to generate images on the server using WPF. It is possible to take a string of xaml and create bitmap from this.
I've written a blogpost about this at http://geekswithblogs.net/tkokke/archive/2009/06/01/image-generation-in-php-using-wpf.aspx In the example I've got a method that returns a byte array, but it shouln't be too hard to change this to save the stream to disk.
Just use the example to create your own little wpf tool to save xaml to pngs. If you need any help with this, just ask or send me an email.
ksleung
Contributor
5396 points
1,028 Posts
07-09-2009 4:25 AM |
Maybe it will be possible tomorrow using Silverlight!
Seriously, if the SL team fixes the WriteableBitmap security issue, which they promised will do so in SL3 RTW, you could draw your Xaml to a canvas, render to a WriteableBitmap, and convert the WriteableBitmap to a byte array. And tomorrow is the "launch" day for SL3!