我收到一个错误:无法解码图像。提供的图像必须是位图。怎么修?

时间:2019-05-10 14:36:28

标签: java android

我的应用程序是每分钟出租一辆小型摩托车,这是问题所在:我首先启动我的应用程序,一切顺利,然后在Android Studio中单击“应用更改”,就会发生这种情况。我需要做的是,我有很多BitmapDescriptorFactory,也许它们有问题吗?我正在寻找答案的第三天。找不到:(

它会更改群集图标,具体取决于大小:

protected void onBeforeClusterRendered(Cluster<ClusterMarker> cluster, MarkerOptions markerOptions) {
            float zoom = mMap.getCameraPosition().zoom;
            if (zoom > 10) {
                if (cluster.getSize() == 2)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c2, 200, 200)));
                if (cluster.getSize() == 3)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c3, 200, 200)));
                if (cluster.getSize() == 4)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c4, 200, 200)));
                if (cluster.getSize() == 5)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c5, 200, 200)));
                if (cluster.getSize() == 6)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c6, 200, 200)));
                if (cluster.getSize() == 7)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c7, 200, 200)));
                if (cluster.getSize() == 8)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c8, 200, 200)));
                if (cluster.getSize() == 9)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c9, 200, 200)));
                if (cluster.getSize() > 9)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c10, 200, 200)));
                if (cluster.getSize() > 19)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c20, 200, 200)));
                if (cluster.getSize() > 29)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c30, 200, 200)));
                if (cluster.getSize() > 39)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c40, 200, 200)));
                if (cluster.getSize() > 49)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c50, 200, 200)));
                if (cluster.getSize() > 59)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c60, 200, 200)));
                if (cluster.getSize() > 69)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c70, 200, 200)));
                if (cluster.getSize() > 79)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c80, 200, 200)));
                if (cluster.getSize() > 89)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c90, 200, 200)));
                if (cluster.getSize() > 99)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.c100, 200, 200)));
            } else {
                if (getActivity() != null)
                    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resizeMarkerIcon(R.drawable.group_scooter, 100, 100)));
            }

        }

这是我的resizeMarkerIcon方法:

public Bitmap resizeMarkerIcon(int image, int width, int height) {
        Context context = getContext();
        if (context != null) {
            BitmapDrawable bitmapDrawable1 = (BitmapDrawable) getResources().getDrawable(image);
            Bitmap b = bitmapDrawable1.getBitmap();
            return Bitmap.createScaledBitmap(b, width, height, false);
        } else {
            return null;
        }
    }
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: eu.quick_app.eu, PID: 23838
    com.google.maps.api.android.lib6.common.apiexception.a: Failed to decode image. The provided image must be a Bitmap.
        at com.google.maps.api.android.lib6.impl.n.a(:com.google.android.gms.dynamite_mapsdynamite@17122081@17.1.22 (100400-245988633):4)
        at com.google.maps.api.android.lib6.impl.r.a(:com.google.android.gms.dynamite_mapsdynamite@17122081@17.1.22 (100400-245988633):5)
        at com.google.maps.api.android.lib6.impl.dh.<init>(:com.google.android.gms.dynamite_mapsdynamite@17122081@17.1.22 (100400-245988633):15)
        at com.google.maps.api.android.lib6.impl.be.a(:com.google.android.gms.dynamite_mapsdynamite@17122081@17.1.22 (100400-245988633):355)
        at com.google.android.gms.maps.internal.m.a(:com.google.android.gms.dynamite_mapsdynamite@17122081@17.1.22 (100400-245988633):396)
        at hj.onTransact(:com.google.android.gms.dynamite_mapsdynamite@17122081@17.1.22 (100400-245988633):4)
        at android.os.Binder.transact(Binder.java:667)
        at com.google.android.gms.internal.maps.zza.zza(Unknown Source:10)
        at com.google.android.gms.maps.internal.zzg.addMarker(Unknown Source:54)
        at com.google.android.gms.maps.GoogleMap.addMarker(Unknown Source:48)
        at com.google.maps.android.MarkerManager$Collection.addMarker(MarkerManager.java:154)
        at com.google.maps.android.clustering.view.DefaultClusterRenderer$CreateMarkerTask.perform(DefaultClusterRenderer.java:865)
        at com.google.maps.android.clustering.view.DefaultClusterRenderer$CreateMarkerTask.access$2100(DefaultClusterRenderer.java:805)
        at com.google.maps.android.clustering.view.DefaultClusterRenderer$MarkerModifier.performNextTask(DefaultClusterRenderer.java:644)
        at com.google.maps.android.clustering.view.DefaultClusterRenderer$MarkerModifier.handleMessage(DefaultClusterRenderer.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6806)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

有什么问题吗?如果需要更多代码,请告诉我。

0 个答案:

没有答案