2013-04-10 32 views
2

這是我到目前爲止有:Windows Phone 8:如何將一個不可見的地圖渲染爲位圖?

const int imgSize = 210; 
Map tempMap = new Map { Width = imgSize, Height = imgSize }; 
// ... adding some layers, setting the view 
Size size = new Size(imgSize, imgSize); 
tempMap.Measure(size); 
tempMap.Arrange(new Rect(new Point(0, 0), size)); 
tempMap.UpdateLayout(); 

WriteableBitmap bmp = new WriteableBitmap(imgSize, imgSize); 
bmp.Render(tempMap, null); 
bmp.Invalidate(); 
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); 
string filename = "/Shared/ShellContent/" + /* ... file name */ ".jpg"; 
using (IsolatedStorageFileStream stream = store.OpenFile(filename, FileMode.OpenOrCreate)) 
    bmp.SaveJpeg(stream, imgSize, imgSize, 0, 100); 

tile.Update(new FlipTileData 
{ 
    // ... set other properties 
    BackgroundImage = new Uri("isostore:" + filename, UriKind.Absolute) 
}); 

我想更新與地圖(WP8的一個,從諾基亞)的圖像的動態磁貼。根據this answer,即使從不是可視樹的一部分的UIElements也可以用WriteableBitmap來渲染;然而,我的形象只是黑色。這是Map控件的問題,還是我做錯了什麼?

編輯1:Windows Phone WriteableBitmap類似乎與the one documented on MSDN完全不同。奇怪的。

編輯2:Documentation for the Silverlight WriteableBitmap

編輯3:部分進步! 添加以下三行:

tempMap.Width = imgSize // right before the measure call. DO NOT set the height. 
(Content as Grid).Children.Add(tempMap) // right after creating tempMap. (your layout may vary) 
(Content as Grid).Children.Remove(tempMap) // after you're done. (your layout may vary) 

這將導致一個完全藍色圖像,而不是完全黑色的。更改tempMap.Center和tempMap.ZoomLevel對瓦片沒有影響;調用tempMap.SetView具有在所有沒有影響(調試,我留在我的應用程序頁面的地圖,以便我可以看到通話的效果 - 瓦是地圖上看起來像在頁面什麼)

回答

1

我自己試過這個,也無法讓它工作。儘管只是使用了Bing的靜態地圖API,但我已經解決了這個問題。然後,我可以下載一張地圖,指定爲我想要的確切尺寸,然後使用它。以下鏈接顯示如何使用它,並提供獲取API密鑰的鏈接(僅需要一秒)。

http://bingmapsdemos.sharepoint.com/Pages/BingMapsStaticMaps.aspx