Listed below are articles related to Out-of-Browser. This represents only a small portion of the content available on the website. Please visit the home page to see current entries and other categories.

Using WriteableBitmap to Create Images in Silverlight

Recently, a friend had a question on how you'd create a compressed image from what was being displayed by his Silverlight application. He knew he needed to use a WriteableBitmap but wasn't sure how he'd get from there to then having a PNG or JPEG file. Any files that he did manage to generate were way too large in file size.

I did some checking around and found a great library on CodePlex called ImageTools. I really like this library because it does both PNG/JPEG encoding and then handles the compression as well.

I've created a sample project that illustrates how you'd use that library to create PNG and JPEG files from your WriteableBitmap in Silverlight (download the sample project or view online demo).

First a couple caveats about running this code. You can extract it and hit F5, but you’ll need to right-click on the app to install it and then run it in OOB mode. The reason I did this is so I could save the generated images to the “My Images” folder and see how big they actually get. When you’re done you can launch the app from your desktop and then right-click on it to uninstall the app from your machine (or you can always uninstall it from the Control Panel).

The online demo will let you save the generated image as either a PNG or JPEG, but only if you've first installed the app and then run it in Out of Browser mode. These images are named "masoli.png" and "masoli.jpg" and are saved to your "My Pictures" folder.

This is a simple and straight-forward example with not a lot to it, hence no MVVM to confuse those new to Silverlight. I believe this is a good illustration of how you can create a compressed PNG or JPEG image from a WriteableBitmap in Silverlight.

tags: Silverlight | Out-of-Browser | WriteableBitmap