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?
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?
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.
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.