1

我正在使用带有画布的普通视图我使用以下代码将视图内容获取到位图

this.setDrawingCacheEnabled(true); gSaveBitmap= this.getDrawingCache();

但它给了我以下错误。

    FATAL EXCEPTION: main
java.lang.IllegalArgumentException: bitmap size exceeds 32bits
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:695)
at android.view.View.buildDrawingCache(View.java:6630)
at android.view.View.getDrawingCache(View.java:6475)
at android.view.ViewGroup.drawChild(ViewGroup.java:1657)    
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
at android.view.ViewGroup.drawChild(ViewGroup.java:1730)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
at android.view.ViewGroup.drawChild(ViewGroup.java:1730)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
at android.view.View.draw(View.java:6973)
at android.widget.FrameLayout.draw(FrameLayout.java:357)
at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
at android.view.ViewGroup.drawChild(ViewGroup.java:1730)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
at android.view.View.draw(View.java:6973)
at android.widget.FrameLayout.draw(FrameLayout.java:357)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1997)
at android.view.ViewRoot.draw(ViewRoot.java:1600)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1321)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1957)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4277)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)

如果你们有解决方案,请告诉我。以下是我的 onDraw()。

    @Override
protected void onDraw(Canvas canvas) 
{       
    try
    {
        super.onDraw(canvas);


            Matrix matrix = canvas.getMatrix();
            matrix.preScale(scaleFactor,scaleFactor, (currentScreenX + (MapConfig.getScreenSize().x/2)), (currentScreenY + MapConfig.getScreenSize().y/2));//here
            canvas.setMatrix(matrix);

            try
            {
                if(save_stare)
                {
                    if(gSaveBitmap!=null)
                        canvas.drawBitmap(gSaveBitmap, tileBitmaprect.left, tileBitmaprect.top, null);
                }
            }
            catch(Exception e)
            {
                Log.e("draw xception--- >", e.toString());
            }
        canvas.drawPaint(canvasPaint);          
        if (currentTiles==null)
            return;
        currentTileSet = currentTiles.entrySet();
        currentTileIterator = currentTileSet.iterator();
        Integer col;
        Integer row;

        Bitmap tileBitmap;
        String[] tileRowCol;
        while (currentTileIterator.hasNext())
        {
            Map.Entry<String,Bitmap> me = (Map.Entry<String,Bitmap>)currentTileIterator.next();             
            tileRowCol = me.getKey().toString().split(",");             
            col = Integer.parseInt(tileRowCol[0]);
            row = Integer.parseInt(tileRowCol[1]);
            tileBitmaprect.left = MapUtils.columnToScreen(col);
            tileBitmaprect.top = MapUtils.columnToScreen(row);
            tileBitmaprect.right = tileBitmaprect.left + MapConfig.tileSize;
            tileBitmaprect.bottom = tileBitmaprect.top + MapConfig.tileSize;
            tileBitmap = (Bitmap)me.getValue();
            if ((tileBitmap != null) && (tileBitmap.equals(MapConfig.noTileBitmap)==false))             
                canvas.drawBitmap(tileBitmap, null, tileBitmaprect, null);
            if (MapConfig.labelTiles)
                canvas.drawText("(" + col + "," + row + ")", tileBitmaprect.left, tileBitmaprect.top, textPaint);           
        }

        Overlays.drawCustomPois(canvas, currentLevel);
        Overlays.drawPanoPointer(canvas, currentLevel);
        Overlays.drawLocationPointer(canvas, currentLevel);
        Overlays.drawPoiBubble(canvas);
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}
4

0 回答 0