Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ground Overlays issue #782

Open
1 of 3 tasks
user790235692 opened this issue Jan 4, 2022 · 1 comment
Open
1 of 3 tasks

Ground Overlays issue #782

user790235692 opened this issue Jan 4, 2022 · 1 comment

Comments

@user790235692
Copy link

user790235692 commented Jan 4, 2022

VERSIONS

  • Xamarin.Forms.GoogleMaps - 3.0.0
  • Xamarin.Forms - 5.0.0.2291

PLATFORMS

  • Android
  • iOS
  • UWP

ACTUAL BEHAVIOR

ACTUAL SCREENSHOTS/STACKTRACE

Screenshot_16

Java.Lang.IllegalArgumentException: 'Failed to decode image. The provided image must be a Bitmap.'
            _Overlay = new GroundOverlay()
            {
                Bounds = new Bounds(new Position(46.32, 5.51), new Position(46.45, 5.61)),
                Icon = BitmapDescriptorFactory.FromBundle("DJI_0962.jpg"),
                Tag = "THE GROUNDOVERLAY",
                ZIndex = 2
            };

            map.GroundOverlays.Add(_Overlay);

I want to ground overlay an image taken by my DJI on the map where is place in the drawable folder of my app. I search a lot but I'm stuck. If soemone have a solution or a lead I wourld be grateful.

@WaynesWrld22
Copy link

This may be the long way around the barn...but I've been using the FromStream option to do this without any problem.

string overlayIndex = "1" //Manage this as you see fit - just and example
_Overlay = new GroundOverlay()
        {
            Bounds = new Bounds(new Position(46.32, 5.51), new Position(46.45, 5.61)),
            Icon = BitmapDescriptorFactory.FromStream(ToStream(bitmap_path), id:overlayIndex),
            //Icon = BitmapDescriptorFactory.FromBundle("DJI_0962.jpg"),
            Tag = "THE GROUNDOVERLAY",
            ZIndex = 2
        };

Then I built a little helper function to read the image into a stream...

public Stream ToStream(SkiaSharp.SKBitmap image)
{
var data = image.Encode(SkiaSharp.SKEncodedImageFormat.Png, 100);
var myStream = new System.IO.MemoryStream();
data.SaveTo(myStream);
return myStream;
}

So into a stream and then out to the BitmapDescriptorFactory.

All the best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants