none
Any change to printing support for BingMaps in UWP applications? RRS feed

  • Question

  • I have an app using bing maps with routing. Right now, I am grabbing the screen once the route is resolved as a bitmap and printing the bitmap. However, I can't get the same amount of detail from the bitmap grab (at least right now) as I see on the screen. (mostly the town names). I tried to render the map in the print preview but am having some trouble with the timing of that.

    Wondering if there are any better choices out there for printing. I read about static maps, but that seems less than desirable.

    Thanks for any help/pointers.

    Monday, September 12, 2016 3:57 PM

Answers

  • You should be able to use RenderTargetBitmap to get an exact copy of what the map control is displaying. If that's insufficient, you can always create a non-visible map control of whatever size/resolution you want (up to the limits of system and graphics memory) and copy the contents of that.
    Monday, September 12, 2016 6:18 PM
    Moderator
  • Here is the code I am using, I don't get what is on the screen, no town names and road details.

                var tempFolder = ApplicationData.Current.TemporaryFolder;
                var file = await tempFolder.CreateFileAsync("routemap.jpg",CreationCollisionOption.ReplaceExisting);
                RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
                await renderTargetBitmap.RenderAsync(MyMap);
                ViewModel.RouteBitmap = renderTargetBitmap;
                var pixels = await renderTargetBitmap.GetPixelsAsync();
                using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
                    byte[] bytes = pixels.ToArray();
                    encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                         BitmapAlphaMode.Premultiplied,
                                         (uint)renderTargetBitmap.PixelWidth, (uint)renderTargetBitmap.PixelHeight,
                                         600, 600, bytes);
                    await encoder.FlushAsync();
                }

    MyMap is the name of the map control.

    Any hints on how to get a better bitmap would be appreciated.

    Thanks.

    Monday, September 12, 2016 11:21 PM

All replies

  • You should be able to use RenderTargetBitmap to get an exact copy of what the map control is displaying. If that's insufficient, you can always create a non-visible map control of whatever size/resolution you want (up to the limits of system and graphics memory) and copy the contents of that.
    Monday, September 12, 2016 6:18 PM
    Moderator
  • Here is the code I am using, I don't get what is on the screen, no town names and road details.

                var tempFolder = ApplicationData.Current.TemporaryFolder;
                var file = await tempFolder.CreateFileAsync("routemap.jpg",CreationCollisionOption.ReplaceExisting);
                RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
                await renderTargetBitmap.RenderAsync(MyMap);
                ViewModel.RouteBitmap = renderTargetBitmap;
                var pixels = await renderTargetBitmap.GetPixelsAsync();
                using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
                    byte[] bytes = pixels.ToArray();
                    encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                         BitmapAlphaMode.Premultiplied,
                                         (uint)renderTargetBitmap.PixelWidth, (uint)renderTargetBitmap.PixelHeight,
                                         600, 600, bytes);
                    await encoder.FlushAsync();
                }

    MyMap is the name of the map control.

    Any hints on how to get a better bitmap would be appreciated.

    Thanks.

    Monday, September 12, 2016 11:21 PM
  • That's the right way to do it. When I run that code I get an exact copy of what the map control is displaying.
    Friday, September 16, 2016 4:59 PM
    Moderator
  • Have a bit more detail on this, the problem I am seeing is that the town/street names are very light. Onscreen, the map control shows these as light text but when I capture the bitmap the names are very light. So light in fact, I thought they were missing.
    Friday, December 2, 2016 3:33 AM