Skip to main content

Microsoft Silverlight

Answered Question Creating images from xaml...RSS Feed

(0)

Cleon26
Cleon26

Member

Member

392 points

111 Posts

Creating images from xaml...

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.soman
milind.s...

Member

Member

389 points

72 Posts

Re: Creating images from xaml...

Even I faced this need few days back. There is no way from the tools but a trick.

  1. Have a black/white (depends on outer colors of your graphic) path behind your graphic.
  2. Close all the other panels in blend so that you can get maximum space for your graphic on the screen.
  3. Take a print screen
  4. Go to photoshop/Fireworks & remove the black color.

Limitation with this trick is, the maximum size of image you can get is less than your screen resolution.

Please "Mark as Answer" if this answered your question.

Sr. User Experience Consultant
SpadeWorx Software Services,
Pune, India.

sorskoot
sorskoot

Member

Member

241 points

42 Posts

Answered Question

Re: Creating images from xaml...

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.

 

~~ Dawn is nature's way of telling you to go to bed ~~

Check my weblog at blog.timmykokkke.com

If this answers your question, please mark it so.

ksleung
ksleung

Contributor

Contributor

5396 points

1,028 Posts

Re: Creating images from xaml...

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!

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities