Tutorial :Does WriteableBitmap has new features in Silverlight 4?


and if someone could give me an example on how to use it, with a stream? (not sure how that works) I know how to create a BitmapImage from an URI now I need to convert this image to a WriteableBitmap, but I get a null exception error with something like this:

BitmapImage image = new BitmapImage(new Uri("http://www.example.com/example.png"));  WriteableBitmap newImage = new WriteableBitmap(image);  


In short: Nope, there are no new features in Silverlight 4. The WriteableBitmapEx tries to compensate the missing functionality.

Regarding your real problem: You should add a handler to the BitmapImage.ImageFailed event to see if there's an error when the image should be downloaded. And you you should create the WriteableBitmap in the ImageOpened event handler.

var image = new BitmapImage(new Uri("http://www.example.com/example.png"));  WriteableBitmap newImage = null;  image.ImageOpened += (s, e) => newImage = new WriteableBitmap(image);  

Please also note that cross-domain references are permitted. See the MSDN page for details. You should put the image into the Web Project's ClientBin folder and use a relative path instead.

As an alternative you can also compile the image into the assembly as resource and load it from there. The WriteableBitmapEx has an extension method to make this task a bit easier. But keep in mind that this blows the assembly size up and the initial XAP loading time will increase.

// Load an image from the calling Assembly's resources only by passing the relative path  var writeableBmp = new WriteableBitmap(0, 0).FromResource("example.png");  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »