I get an error when I load a background image before I load another image on top of it. The logcat points to memory error but the background is only 17kb in size.
Here the code in sequence of events
package com.firm.armouredassault;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.os.Bundle;
public class StartNewGame extends Activity {
MyGame ourView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//setContentView(R.drawable.canvas);
ourView = new MyGame(this);
setContentView(ourView);
}
}
MyGame.java:
package com.firm.armouredassault;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;
public class MyGame extends View {
Bitmap BTank, TShell;
public MyGame(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(),
R.drawable.bluetanksm), 10, 200, null);
}
}
If the option don’t vary when you call BitmapFactory.decodeResource, can’t you put the result in a field and reuse this value for every call to onDraw.
I don’t think this is an answer or will solve your problem, but I guess your app will feel a lot better no to have to decompress a jpeg everytime you want to display it on screen.