dotnet / dotnet/maui

CaptureAsync() doesn't save Maps content

Open
#12,876 15 comments 5 reactions 0 assignees View on GitHub
area-controls-map area-essentials platform/android s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 10h
Merged PRs (30d)
306

Description

### Description

When trying to capture the content of a map in a screenshot, the map output is transparent - despite the other elements being properly captured (buttons, etc.).

In Xamarin.Forms, I used to go with Map.TakeSnapshot() to achieve it.

![image](https://user-images.githubusercontent.com/38657416/214255557-1d0b87d7-2aba-492c-94fc-3fa9aa9b2e63.png)

### Steps to Reproduce

From scratch:
1. Create new .net MAUI app
2. Add Microsoft.Maui.Controls.Maps package
3. Setup Maps in MauiProgram.cs and AndroidManifest.xml
4. Add a map element named "map" on a page (top half)
5. Add an image named "screenshot" (bottom half)
6. Add a button with a click event
7. Set the click event content to
```
private async void Button_Clicked(object sender, EventArgs e)
{
IScreenshotResult screen = await map.CaptureAsync();
Stream stream = await screen.OpenReadAsync();
var image = ImageSource.FromStream(() => stream);
screenshot.Source = image;
}
```
8. Run the app and hit the button
9. Expected result: The image "screenshot" should show the map
Current result: Only the Google logo and the zoom buttons are shown, the map content being transparent (we can see the background)

From the existing repository
1. Download repository
2. Go to AndroidManifest and update the API Key with one of your own,
3. Run the app and hit the "Take screenshot and see below" button
4. See the image output

### Link to public reproduction project repository

https://github.com/Davidoutz/MapsScreenshotBug

### Version with bug

7.0 (current)

### Last version that worked well

Unknown/Other

### Affected platforms

Android, I was *not* able test on other platforms

### Affected platform versions

Android 11

### Did you find any workaround?

Not yet

### Relevant log output

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.