This project is read-only.

getting my Canvas to ImageTools' Image..

Nov 24, 2010 at 2:34 AM
Edited Nov 24, 2010 at 3:20 AM

In version 0.3, there seem to be no ImageTools.Image. I found out that I should use ImageTools.ExtendedImage type instead, but am not able to get it working.

I'd like to take my Canvas and get a stream from it.

ExtendedImage img = ImageTools.ImageExtensions.ToImage(this.canvas1); // try#1
ExtendedImage img = this.canvas1.ToImage();  // try#2
MemoryStream mstream = new MemoryStream();
JpegEncoder encoder = new JpegEncoder();
encoder.Encode(img, mstream);
mstream.Seek(0, SeekOrigin.Begin);

When I run it, both try#1 and #2 throw me an error: "Bitmap cannot accessed". How do I convert my Canvas to ExtendedImage?? Thanks.


ps. Does a sample on this page(here) supposed to work with v0.3??

Nov 24, 2010 at 3:30 AM

Adding to my question..

I found out it's not the version of ImageTools. It DOES work fine when there is no image object in my canvas. But, once I've added a silverlight image object to my canvas and tried to do ImageExtensions.ToImage function, it throw me that error. Is something wrong with my image that make things not work?

The image on Canvas is set like below:

Uri imguri = new Uri("http://myserver/myimage.jpg", UriKind.Absolute);
BitmapImage bitmapimg = new BitmapImage(imguri);
this.myImage.Source = bitmapimg;

The image SHOWS okay on silverlight control on the web browser. Thanks.

Nov 27, 2010 at 8:10 PM

I figured out the issue. It's not ImageTools' issue. It's SL security. When the bitmap needs to be accessed, it requires the SL App to run on the same domain. The absolute URI I used for testing was my desktop server and the SL app was running on VS Development server. The image loaded okay because I had crossdomain xml on my desktop server. But when accessing bitmap, that was not enough, and it trowed an error. This post helped: