Jedi Schmedi
Jedi Schmedi

Reputation: 818

Replacing current canvas in onDraw

I got a surfaceView which in the onDraw function I try to change the current canvas by creating a new canvasBitMap:

Bitmap.Config conf = Bitmap.Config.ARGB_8888;
canvasBitmap = Bitmap.createBitmap((int) canvas.getWidth(), (int) canvas.getHeight(), conf); 
canvas = new Canvas(canvasBitmap);
Temp temp = new Temp(canvas);

I then try to print the canvas ID to see if temp.getCanvas is the same as canvas:

Log.d("Debug", "Canvas: " + canvas);
Log.d("Debug", "Temp Canvas: " + Temp.getCanvas());

The result from the printout is:

Canvas: android.view.GLES20RecordingCanvas@34cbdc63 
Temp Canvas: android.graphics.Canvas@276f78f4

Question is simple, Why arent they the same?

br

Upvotes: 0

Views: 297

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93561

Because you created a new one. The incoming canvas is a canvas that points to the screen (or more properly, to a buffer in the graphics card that will be drawn to the screen). The one you created draws to a new in-memory bitmap that you created in your create bitmap function, and will draw to that bitmap, not the screen.

Upvotes: 1

Related Questions