Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to decode image. The provided image must be a Bitmap

BitmapDescriptor bmpD = BitmapDescriptorFactory.fromResource(R.raw.podval);

    Log.d("myLog", ":" + bmpD);

    GroundOverlayOptions newarkMap = new GroundOverlayOptions()
            .image(bmpD)
            .position(sydney, 8600f, 6500f);
    Log.d("myLog", ":" + newarkMap);
    GroundOverlay imageOverlay = mMap.addGroundOverlay(newarkMap);

Failed to decode image. The provided image must be a Bitmap. But in log I got :com.google.android.gms.maps.model.BitmapDescriptor@58e0ee6 :com.google.android.gms.maps.model.GroundOverlayOptions@1ea9c27

Also I converted jpg image to bmp, after failing to convert it here

Help please.

like image 508
Asset Bekbossynov Avatar asked Sep 30 '17 09:09

Asset Bekbossynov


1 Answers

See https://stackoverflow.com/a/45564994/2914140 for vector drawables (SVG).

private BitmapDescriptor bitmapDescriptorFromVector(Context context, @DrawableRes int vectorResId) {
        Drawable vectorDrawable = ContextCompat.getDrawable(context, vectorResId);
        vectorDrawable.setBounds(0, 0, vectorDrawable.getIntrinsicWidth(), vectorDrawable.getIntrinsicHeight());
        Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(), vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        vectorDrawable.draw(canvas);
        return BitmapDescriptorFactory.fromBitmap(bitmap);
}
like image 194
CoolMind Avatar answered Nov 01 '22 11:11

CoolMind