无法解码图像。提供的图像必须是位图

问题描述 投票:3回答:2
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,之后无法将其转换为bmp

请帮忙。

android google-maps bitmap
2个回答
1
投票

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


0
投票

有关矢量绘图(SVG),请参阅https://stackoverflow.com/a/45564994/2914140

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);
}
© www.soinside.com 2019 - 2024. All rights reserved.