0

I have several UIElements, including an Image (with an External URL image), and then I want to catch a thumbnail of these elements, so I use WriteableBitmap to catch the pixels for each UIElement.

However, when I try to catch the pixel for the Image using:

WriteableBitmap wb = new WriteableBitmap(image, new ScaleTransform()
                     {
                         ScaleX = 0.5,
                         ScaleY = 0.5,
                     });
...
wb.GetPixeli(x, y); // Throws exception

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap(v=vs.95).aspx

The WriteableBitmap class has a security model that restricts access to the Pixels array, if the WriteableBitmap is constructed using cross-domain content. For example, a WriteableBitmap that is constructed using a BitmapImage referencing a URL that comes from another domain does not permit access to its Pixels array. The restriction extends to any UI element that uses a URL-derived property for setting some or all of its content. In particular, this restriction applies to the "Grab a frame of a running video from MediaElement" scenario. If the MediaElement.Source references a video file from another domain, the WriteableBitmap created by referencing the MediaElement as the element source restricts access to the Pixels array.

So in order to catch the thumbnail of these several UIElements (including an Image element) do I have to download the image to a temp directory and then render it?

Peter Lee
  • 12,931
  • 11
  • 73
  • 100

1 Answers1

0

My advice would be to double-check what you're trying to do - if you're writing a Silverlight application, chances are you want to reduce the amount of data flowing to the client, before downloading the full image(s). Would it be better to produce these thumbnails server-side (either on-the-fly or caching) and deliver them already smaller, and where you can use the full .NET framework to produce the thumbnails?

Dan Fox
  • 143
  • 8
  • As a matter of factor, it is the SERVER wants to have a thumbnail of the elements (including one image element with external URL). – Peter Lee Nov 16 '12 at 18:33
  • I don't quite understand then - the MSDN snippet you've quoted refers to the Silverlight framework and not the .NET framework that you'll be running on the server? So you might be able to use the WritePixels method of WriteableBitmap? – Dan Fox Nov 19 '12 at 08:18