Select to view content in your preferred language

Silverlight API- Map Screenshot into Base64string and save in Database

3105
6
12-03-2010 12:22 PM
YamunadeviRathinasamy
New Contributor II
I used WriteableBitmap to take the screenshot of the Image and convert that into Base64 string using FJCore. Due to Domain Issues with WriteableBitmap I am not able to read Pixels from WriteableBitmap.

getting the following Security error:
"WriteableBitmap has protected content. Pixel access is not allowed."

Method Used to convert WritableBitmap to base64string:
public static string ConvertImagetoString(WriteableBitmap bitmap)
{

int width = bitmap.PixelWidth;
int height = bitmap.PixelHeight;
int bands = 3;
byte[][,] raster = new byte[bands][,];
for (int i = 0; i < bands; i++)
{
raster = new byte[width, height];
}
int[] bitpixes = bitmap.Pixels.ToArray();
for (int row = 0; row < height; row++)
{
for (int column = 0; column < width; column++)
{
int pixel = bitpixes[width * row + column];
raster[0][column, row] = (byte)(pixel >> 16);
raster[1][column, row] = (byte)(pixel >> 8);
raster[2][column, row] = (byte)pixel;
}
}

ColorModel model = new ColorModel { colorspace = FluxJpeg.Core.ColorSpace.RGB };
FluxJpeg.Core.Image img = new FluxJpeg.Core.Image(model, raster);
MemoryStream stream = new MemoryStream();
JpegEncoder encoder = new JpegEncoder(img, 90, stream);
encoder.Encode();
stream.Seek(0, SeekOrigin.Begin);
byte[] binaryData = new Byte[stream.Length];
long bytesRead = stream.Read(binaryData, 0, (int)stream.Length);
string base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length);
return base64String;
}

Function call:
WriteableBitmap redlinescreenshot = new WriteableBitmap(this.TheMap, new TranslateTransform());
string base64String = ConvertImagetoString(redlinescreenshot);


Any help Appreciated...Urgent!!!! Thanks
0 Kudos
6 Replies
dotMorten_esri
Esri Notable Contributor
You are getting that error because you are trying to read the pixels of an image that contains pixels merged from images coming from a different domain than your .xap file. For security reasons, silverlight will block pixel read access to any images (or composites) coming from a different domain.
You got two options:
- Use a proxy on your local server where the .xap recides and use the ProxyUrl to route the image download through that.
- Upgrade to v2.1. v2.1 uses a different approach for retrieving images, so for most services you won't see this issue (however there still might be some layers that doesn't use this approach).
0 Kudos
komalagarwal
Deactivated User
Hi Yamuna,

Is your issue resolved? I have a similar requirement where I need to convert Map into Byte array.Can you please share your solution/Code.

For your reference I am using Silvelight api 2.1
0 Kudos
MohamedAhmed
New Contributor
i face the same problem how we can craet the proxy or how we can send the map image to wcf service
0 Kudos
LuisCÃ_spedes
Deactivated User
Any help to all of us newbies that dont know how to go about this . . . .
0 Kudos
YamunadeviRathinasamy
New Contributor II
I resolved this issue by deploying the app into my webserver which is my SOM as well.
The Mapservice path is same as the webserver path, same domain so I am getting the Map bitmap pixels.
0 Kudos
KalongiDrake
Deactivated User
I resolved this issue using the first approach mentioned by SharpGIS. You can download the ashx generic handler that serves as the proxy here. The readme file explains how to edit the config file to direct service requests through the proxy.
0 Kudos