我正在使用 c# 和 XAML 开发 Metro App。
在我的应用程序中,我需要将静态地图保存为来自位置(经度、纬度)的图像:http: //dev.virtualearth.net/REST/v1/Imagery/Map/Road/47.619048,-122.35384/15 ?mapSize=500,500&key=BINGKEY
我尝试了许多方法来通过将 HTTPRequest 发送到该 URL 来从中创建图像,但都是徒劳的。
例如:
HttpWebRequest httpWebRequest = (HttpWebRequest)result.AsyncState;
WebResponse response = httpWebRequest.EndGetResponse(result);
// Retrieve the reponse data.
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
string xml = reader.ReadToEnd();
System.Text.Encoding enc = System.Text.Encoding.UTF8;
Clsses.Common.Instance.imageBytes = enc.GetBytes(xml);
Stream stream = new MemoryStream(Clsses.Common.Instance.imageBytes);
InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
DataWriter writer = new DataWriter(randomAccessStream.GetOutputStreamAt(0));
writer.WriteBytes(Clsses.Common.Instance.imageBytes);
var result1 = await writer.StoreAsync();
WriteableBitmap wb = new WriteableBitmapresult1 1);
MemoryStream ms = new MemoryStream();
using (IRandomAccessStream writeStream = await sampleFile1.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(new Guid(), writeStream);
encoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied, (uint)wb.PixelWidth, (uint)wb.PixelHeight, 96, 96, Clsses.Common.Instance.imageBytes);
await encoder.FlushAsync();
}
请帮我将其另存为图像对象。