获取位图时崩溃

时间:2011-08-08 06:14:39

标签: java android eclipse

如果我注释掉解码bitmap和(xposypos的行,因为他们使用它)它不会崩溃。但是,如果它们是uncommented,它就会崩溃。我不知道为什么。

public class ClSprite implements Parcelable{

    private Bitmap SpriteBitmap;    // the actual bitmap
    private boolean Touched;    // if droid is touched/picked up
    private int XVelocity;
    private int YVelocity;
    private int XPosition; 
    private int YPosition;
    private boolean Visible;
    private String SpriteType;
    private int BitmapLocation;


    public ClSprite(int givenBitmapLocation, int xPosition, int yPosition, int VelocityX, int VelocityY, String spriteType)
    {
        //Needs this constructor filled in.
        BitmapLocation = givenBitmapLocation;
        SpriteBitmap = BitmapFactory.decodeResource(Game.context.getResources(),R.drawable.icon);
        XPosition = xPosition - SpriteBitmap.getWidth()/2;
        YPosition = yPosition - SpriteBitmap.getHeight()/2;
        XVelocity = VelocityX;
        YVelocity = VelocityY;
        Visible = true;
        SpriteType = spriteType;
    }

1 个答案:

答案 0 :(得分:0)

我敢打赌你的LogCat会显示OutOfMemoryError。像这样:“OutOfMemoryError:位图大小超过VM预算”。

如果是这样,您需要修复或动态缩放位图。请看这里:

http://code.google.com/p/android/issues/detail?id=8488