I have an expensive background drawing operation (basically drawing
lots of squares in random colors), so I would like to draw onto the
Canvas programmatically, get the Bitmap that was drawn, and then call
Canvas.drawBitmap with that Bitmap for subsequent draws.

Here is my code:

        private Bitmap bitmap = null;

        public void draw(Canvas canvas) {
                if (bitmap != null) {
                        canvas.drawBitmap(bitmap, m, null);
                        return;
                }

                bitmap = Bitmap.createBitmap(canvas.getWidth(), 
canvas.getHeight(),
Bitmap.Config.ARGB_8888);
                canvas.setBitmap(bitmap);
                for (int y = 0, maxY = canvas.getHeight(); y < maxY; 
y+=cellSize) {
                        for (int x = 0, maxX = canvas.getWidth(); x < maxX; 
x+=cellSize) {
                                int color = r.nextInt(0xffffff) + 0xff000000;
                                cr.draw(canvas, color, x, y);
                        }
                }
        }

The code above works when I comment out the bitmap creation and
canvas.setBitmap(bitmap). Any idea what I'm doing wrong here?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to