You can use the ArcGIS Silverlight API to output a map to an image by sending an HTTP request to the server or directly using the writeablebitmap class on the client.
The HTTP Request Method sent to the server can output maps within the specified rectangle range, set the control reference, and support PNG, JPG, BMP, and other image formats, however, this method can only be used for a single map service at a time. In other words, when we add multiple map services, we cannot output all the map services in the output area together; this method does not support graphiclayer layer output.
Select map output area
Images returned by the server
Private
Void exportimage (ESRI. ArcGIS. Client. Geometry. Geometry extent)
{
Try
{
Envelope SENV = extent. extent;
Stringbuilder Surl =
New stringbuilder ();
Surl. append ("http: // Lingy/ArcGIS/rest/services/dxmap/mapserver ");
Surl. append ("/export? ");
Surl. append ("F = JSON ");
Surl. append (string. format ("& bBox = {0}, {1}, {2}, {3}", SENV. xmin, SENV. ymin, SENV. xmax, SENV. ymax ));
Surl. append ("& format = ");
Surl. append ("PNG ");
Httpwebrequest request = (httpwebrequest) httpwebrequest. Create (sburl. tostring ());
Request. begingetresponse (New
Asynccallback (exportcall), request );
}
Catch (exception ex)
{
MessageBox. Show ("image export failed:" + ex. tostring ());
}
}
Private
Void exportcall (iasyncresult asynchronousresult)
{
This. Dispatcher. begininvoke (delegate ()
{
Try
{
Httpwebrequest request = (httpwebrequest) asynchronousresult. asyncstate;
Httpwebresponse response = (httpwebresponse) request. endgetresponse (asynchronousresult );
Stream stream = response. getresponsestream ();
Streamreader reader =
New streamreader (Stream );
String result = reader. readtoend ();
String href = result. Split (New
Char [] {'"'}) [3];
Linkimageresult. navigateuri =
New uri (href,
Urikind. Absolute );
}
Catch (exception ex)
{
MessageBox. Show ("image export failed:" + ex. tostring ());
}
});
}
Writeablebitmap can be directly saved to the map control on the client. The saved image format must be encoded by yourself.
Use writeablebitmap source code:
Private
Void button#click (Object sender,
Routedeventargs E)
{
Try
{
Cmapexporttoimage imageexporter =
New cmapexporttoimage ();
Bool bresult = imageexporter. exportpng (mainmap
As uielement );
String strresult = bresult?
"Successful! ":
"Failed! ";
MessageBox. Show ("image export" + strresult );
}
Catch (exception per)
{
String MSG = per. message;
}
}
For more information about cmapexporttoimage and cpngencoder. CS files, see the attachment below.
Cmapexporttoimage.txt (2.67 KB)
Cpngencoder.txt (8.36 KB)
Go to: http://www.gisall.com/html/72/124272-5867.html