0

When I create a new Canvas in onDraw() like this:

Canvas c = new Canvas(myBitmap);

and then use this to draw something, it dosen't work.

But when I use the canvas parameter from onDraw(Canvas canvas), it works. Can someone tell me why?

Rohan Singh
  • 20,497
  • 1
  • 41
  • 48
  • 1
    What do you mean by "it doesn't work". You are probably going to have to edit your question to clarify that if you're looking for a good answer. – Rohan Singh Mar 16 '12 at 09:51

2 Answers2

0

Try out this -

Bitmap  bitmap = Bitmap.createBitmap( view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas); 
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);

And, see the related question from Stackoverflow

and, try out the Sampleapp also.

Community
  • 1
  • 1
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
0

What kind of error are you getting? if you want to just draw a bitmap use the following code:

    @Override
           protected void onDraw(Canvas canvas) 
           {
                canvas.drawBitmap(bak, 0, 0, null);
           }

Where "bak" is a bitmap. There is no need of a creating another extra Canvas again inside onDraw as its a redundancy.

HjK
  • 3,513
  • 1
  • 17
  • 23
  • but I want to draw a white area 320*240 .....when i use the canvas above like canvas.drawColor(Color.WHITE); The whole screen is white – octobershiner Mar 18 '12 at 07:56