【问题标题】:Failed to decode image. The provided image must be a Bitmap无法解码图像。提供的图像必须是位图
【发布时间】:2018-03-12 02:47:18
【问题描述】:
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);

无法解码图像。提供的图像必须是位图。 但是在日志中我得到了:com.google.android.gms.maps.model.BitmapDescriptor@58e0ee6 :com.google.android.gms.maps.model.GroundOverlayOptions@1ea9c27

我也将jpg图像转换为bmp,在这里转换失败后

请帮忙。

【问题讨论】:

    标签: android google-maps bitmap


    【解决方案1】:

    请参阅https://stackoverflow.com/a/45564994/2914140 了解矢量可绘制对象 (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);
    }
    

    【讨论】:

      【解决方案2】:

      将您的图像放在可绘制文件夹中,而不是原始文件夹中。还要确保资源是有效的图像文件。

      【讨论】:

      • 不错的尝试))我认为没关系
      • 您确定 podval 是有效图像吗?
      猜你喜欢
      • 2020-05-23
      • 1970-01-01
      • 2019-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多