You're missing the point, which is to get access to the bytes of a WriteableBitmap in order to write out an image file, not just display it online. Having said that, I take back my previous post. REST is the answer, if you're returning image bytes instead of a URL. I just tried it, created a WriteableBitmap from the request stream and it worked! I think I finally have the workaround needed for PDF creation.
private void BitmapTest()
{
string sError = "";
try
{
string sURL = "http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer/export";
string sData = "?f=image";
int iWidth = (int)MyMap.Width;
int iHeight = (int)MyMap.Height;
sData += "&size=" + iWidth.ToString() + "," + iHeight.ToString();
sData += "&bbox=-121,32,-113,36";
Uri uri = new Uri(sURL + sData);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.BeginGetResponse(new AsyncCallback(RespCallback), req);
}
catch (WebException e)
{
sError = e.Message;
}
catch (Exception e)
{
sError = e.Message;
}
}
private void RespCallback(IAsyncResult ar)
{
string sError = "";
try
{
HttpWebRequest req = (HttpWebRequest)ar.AsyncState;
HttpWebResponse res = (HttpWebResponse)req.EndGetResponse(ar);
if (res.StatusCode == HttpStatusCode.OK)
{
string sType = res.ContentType;
int iLen = (int)res.ContentLength;
Stream stream = res.GetResponseStream();
this.Dispatcher.BeginInvoke(() => StreamToBitmap(stream));
}
}
catch (WebException e)
{
sError = e.Message;
}
catch (Exception e)
{
sError = e.Message;
}
}
private void StreamToBitmap(Stream s)
{
string sError = "";
try
{
BitmapImage bmi = new BitmapImage();
bmi.SetSource(s);
WriteableBitmap wbm = new WriteableBitmap(bmi);
int iWidth = wbm.PixelWidth;
int iHeight = wbm.PixelHeight;
int i = wbm.Pixels[0]; // Bingo!
}
catch (Exception e)
{
sError = e.Message;
}
}