views:

107

answers:

4

Hi all,

I have an Esri map in silverlight and I am trying to get a screenshot. However, I am facing cross-domain content protection for writeablebitmap, saying "Pixels are not accessible".

Is there a way that I can disable this? or any other work around in silverlight 3 or 4?

A: 

If the source of the bitmap is another domain, the simple answer is no. I'm not sure how you're trying to take this "screen shot", but it sounds like there are good security reasons to stop this... Of course, full (read/write) pixel access is available normally, when your image is in the local domain.

The right way to resolve this, given you seem to want a screenshot of the user's desktop taken, would be to make the Silverlight app require full trust, which is possible since Silverlight 3 (and expanded in Silverlight 4). This does however require it to be an OOB (out of browser app) I believe.

Noldorin
+2  A: 

you can kind of hack around this by rehosting the image. basically you can set up a wcf service on your server that acts as a proxy to the map, then when silverlight does the security check on your media source it will see that it is 'hosted' by your server, then it should let you render it to a Writeable bitmap. though this could obviously greatly increase the load on your server.

luke
+1 for providing an alternative. This is a security feature of Silverlight so obviously you can't just 'work around' it.
Jeff Wilcox
+1  A: 

The simplest way to work around this problem is to make sure that the Silverlight application and the images are hosted from the same domain. Since you are asking this question, I will assume that this is not possible.

Do you control the server where the images are hosted? If so, you can add a Client Access Policy file to enable cross-domain access to the images from your Silverlight app. Then you need to change how you are consuming these images. Instead of setting the Source of the Image element to a URI of the image, use WebClient to download the image as a Stream and set the source of the Image element directly to that Stream. If you do this, you will not run into the cross-domain access violations when trying to access the WriteableBitmap pixels.

KeithMahoney
A: 

I have videos stored on an Amazon cloudfront server with a valid clientaccesspolicy.xml to allow cross domain access for the silverlight host URL and the following function did not allow me to take screen shots of the video and manipulate the pixels until it was replaced with with a WebClient download instead (a WebClient honors the cross domain policy files, you can see it being requested in Fiddler, something that the MediaElement.Source function did not even attempt)

Old none working cross domain code

public LoadVideoFromURL(string url)
{
    var uri = new Uri(url);

    myMediaElement.Source(uri);
}

new working cross domain code

public LoadVideoFromURL(string url)
{
    var uri = new Uri(url);

    //Request the video
    var videoDownloader = new WebClient();

    videoDownloader.OpenReadCompleted += new OpenReadCompletedEventHandler( 
                 (s, args) => myMediaElement.SetSource(args.Result));

    videoDownloader.OpenReadAsync(uri);
}