在nutiteq上绘制标记时,位图大小超过32位

时间:2014-11-06 04:12:32

标签: android bitmap nutiteq

我正在我的Android应用中创建动态地图标记,但有时我得到OutOfMemoryErrorIllegalArgumentException具有相同的logcat错误。这是我绘制多个标记的代码

for (int i = 0; i < lats.size(); i++) {
        // draw marker
        Bitmap markerBitmap = UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.ic_place);
        MarkerStyle markerStyle = MarkerStyle.builder().setBitmap(markerBitmap).setSize(0.5f).setColor(Color.RED).build();

        // define custom label
        try {
            Label markerLabel = new DefaultLabel("", data.get(i));
            // define map location marker, convert to base map coordinate
            MapPos position = maplayer.getProjection().fromWgs84(Double.parseDouble(lngs.get(i)), Double.parseDouble(lats.get(i)));

            // add marker to the current map layer
            markerLayer = new MarkerLayer(maplayer.getProjection());
            marker = new Marker(position, markerLabel, markerStyle, markerLayer);
            markerLayer.add(marker);
            mapView.getLayers().addLayer(markerLayer);
        } catch (Exception e) {
            Log.d("Error Marker", e.getMessage() + " " + e.getCause());
        } catch (OutOfMemoryError e){
            Toast.makeText(getApplicationContext(), "OutOfMemory " + e.getMessage() + " " + e.getCause(), Toast.LENGTH_LONG).show();
            Log.d("OutOfMemory", e.getMessage() + " " + e.getCause());
        }
    }

这是logcat错误

11-05 18:16:18.340  28622-28694/kolek.com.kolekin E/AndroidRuntime? FATAL EXCEPTION: GLThread 657
java.lang.IllegalArgumentException: bitmap size exceeds 32bits
        at android.graphics.Bitmap.nativeCreate(Native Method)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:669)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:649)
        at com.nutiteq.ui.Label.getTextureInfo(Label.java:77)
        at com.nutiteq.ui.DefaultLabel.drawMarkerLabel(DefaultLabel.java:153)
        at com.nutiteq.renderers.MapRenderer3D.updateLabel(MapRenderer3D.java:484)
        at com.nutiteq.renderers.MapRenderer3D.onDrawFrame(MapRenderer3D.java:358)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

11-05 18:29:03.630  32187-32423/kolek.com.kolekin E/AndroidRuntime? FATAL EXCEPTION: GLThread 559
java.lang.OutOfMemoryError
        at android.graphics.Bitmap.nativeCreate(Native Method)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:669)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:649)
        at com.nutiteq.ui.Label.getTextureInfo(Label.java:77)
        at com.nutiteq.ui.DefaultLabel.drawMarkerLabel(DefaultLabel.java:153)
        at com.nutiteq.renderers.MapRenderer3D.updateLabel(MapRenderer3D.java:484)
        at com.nutiteq.renderers.MapRenderer3D.onDrawFrame(MapRenderer3D.java:358)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

有人遇到这种情况吗?我将不胜感激任何帮助。谢谢。

1 个答案:

答案 0 :(得分:0)

你为每个标记做了很多位图复制,为什么不在for()之前放这些行,并为标记使用相同的位图和样式?

        Bitmap markerBitmap = UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.ic_place);
        MarkerStyle markerStyle = MarkerStyle.builder().setBitmap(markerBitmap).setSize(0.5f).setColor(Color.RED).build();

你甚至为每个Marker创建了新的Layer,所以请在():

之前添加这些行
     markerLayer = new MarkerLayer(maplayer.getProjection());
     mapView.getLayers().addLayer(markerLayer);

所以代码是:

    Bitmap markerBitmap = UnscaledBitmapLoader.decodeResource(getResources(), R.drawable.ic_place);
    MarkerStyle markerStyle = MarkerStyle.builder().setBitmap(markerBitmap).setSize(0.5f).setColor(Color.RED).build();

    markerLayer = new MarkerLayer(maplayer.getProjection());
    mapView.getLayers().addLayer(markerLayer);

    for (int i = 0; i < lats.size(); i++) {
        // draw marker
        // define custom label
        try {
           Label markerLabel = new DefaultLabel("", data.get(i));
           // define map location marker, convert to base map coordinate
           MapPos position = maplayer.getProjection().fromWgs84(Double.parseDouble(lngs.get(i)), Double.parseDouble(lats.get(i)));

            // add marker to the current map layer
            marker = new Marker(position, markerLabel, markerStyle, markerLayer);
            markerLayer.add(marker);
        } catch (Exception e) {
            Log.d("Error Marker", e.getMessage() + " " + e.getCause());
        } catch (OutOfMemoryError e){
            Toast.makeText(getApplicationContext(), "OutOfMemory " + e.getMessage() + " " + e.getCause(), Toast.LENGTH_LONG).show();
            Log.d("OutOfMemory", e.getMessage() + " " + e.getCause());
        }
    }