I’m wanting to write a whiteboard app. I have a beginning that renders a bitmap (the drawing page) and then copies that bitmap to the surfaceView. It works perfectly in the emulator, but when I run it on my Samsung Galaxy Ace, it unexpectedly closes. This code:
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "Create surface");
mo_paper = BitmapFactory.decodeResource(getResources(), R.drawable.paper);
Log.d(TAG, "Created paper");
mo_easel = new Canvas();
Log.d(TAG, "Created easel");
mo_easel.setBitmap(mo_paper);
Log.d(TAG, "Set easel");
mo_matrix = new Matrix();
Log.d(TAG, "Assets loaded");
mainThread.setRunning(true);
mainThread.start();
Log.d(TAG, "Threads started");
}
outputs ‘Created easel’ but not ‘Set easel’, so it appears the .setBitmap() method is causing the error.
Bitmaps loaded from resources are immutable. You need to pass a BitmapFactory.Options that tell BitmapFactory that you want the resulting bitmap to be immutable.