簡體   English   中英

是否可以將視圖從Bing Maps渲染到WriteableBitmap?

[英]Is it possible to render a view from Bing Maps to a WriteableBitmap?

案例:Windows Phone 7(Mango)應用程序。

我有一個(數百個)項目列表,其中包含一個地理坐標。 每個項目的參數數據都用於渲染圖像,並且這些圖像顯示在列表框中。

是否可以將WP7 Map元素呈現為writeablebitmap? 如果不是,是否可以從map元素禁用UI手勢,因此它至少表現得像靜態圖像一樣?

如果您只想要地圖的靜態圖像,建議您為Bing地圖使用靜態地圖API,而不是為每個列表項使用Map控件。

靜態地圖API還允許您指定圖像大小,以便可以減少手機的下載大小。

如果仍要使用Bing Map控件,則可以通過將IsHitTestVisible設置為false來禁用UI手勢,例如XAML中的代碼:

<my:Map IsHitTestVisible="False" />

嘗試GFTab評論中建議的示例

為了使其靜態,可以嘗試IsHitTestVisible =“ False”

這是我如何從當前在應用程序中可見的區域中創建輔助磁貼:

    private void pinCurrentMapCenterAsSecondaryTile() {
        try {
            var usCultureInfo = new CultureInfo("en-US");
            var latitude = map.Center.Latitude.ToString(usCultureInfo.NumberFormat);
            var longitude = map.Center.Longitude.ToString(usCultureInfo.NumberFormat);
            var zoom = map.ZoomLevel.ToString(usCultureInfo.NumberFormat);
            var tileParam = "Lat=" + latitude + "&Lon=" + longitude + "&Zoom=" + zoom;
            if (null != App.CheckIfTileExist(tileParam)) return; // tile for exactly this view already exists

            using (var store = IsolatedStorageFile.GetUserStoreForApplication()) {
                var fileName = "/Shared/ShellContent/" + tileParam + ".jpg";
                if (store.FileExists(fileName)) {
                    store.DeleteFile(fileName);
                }
                // hide pushpins and stuff
                foreach (var layer in map.Children.OfType<MapLayer>()) {
                    layer.Visibility = Visibility.Collapsed;
                }
                using (var saveFileStream = new IsolatedStorageFileStream(fileName, FileMode.Create, store)) {
                    var wb = new WriteableBitmap(173, 173);
                    b.Render(
                        map,// the map defined in XAML
                        new TranslateTransform {  
                            // use the transformation to clip the center of the current map-view
                            X = -(map.ActualWidth - 173)/2,
                            Y = -(map.ActualHeight - 173)/2,
                    });
                    wb.Invalidate();
                    wb.SaveJpeg(saveFileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                }
                foreach (var layer in map.Children.OfType<MapLayer>()) {
                    layer.Visibility = Visibility.Visible;
                }
            }

            ShellTile.Create(
                new Uri("/MainPage.xaml?" + tileParam, UriKind.Relative),
                new StandardTileData {
                    BackTitle = "ApplicationName",
                    Count = 0,
                    // You can only load images from the web or isolated storage onto secondary tiles
                    BackgroundImage = new Uri("isostore:/Shared/ShellContent/" + tileParam + ".jpg", UriKind.Absolute),
                });
        } catch (Exception e) {
            // yeah, this is 7331!!11elfelf
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM