views:

61

answers:

1

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);
+1  A: 

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");
Rene Schulte
I tried your idea, now I don't get an error but I don't get an image either.. that means that the server doesn't allow cross domain requests? and thus there's no way I can do it?
david
Check this two links for Cross Domain calls:http://weblogs.asp.net/jgalloway/archive/2008/12/12/silverlight-crossdomain-access-workarounds.aspxhttp://blogs.msdn.com/b/silverlightws/archive/2008/03/30/some-tips-on-cross-domain-calls.aspx
Rene Schulte