amay077 / Xamarin.Forms.GoogleMaps

Map library for Xamarin.Forms using Google maps API
https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps/
MIT License
546 stars 347 forks source link

Ground Overlays issue #782

Open user790235692 opened 2 years ago

user790235692 commented 2 years ago

VERSIONS

PLATFORMS

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 commented 1 year ago

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!