atom feed3 messages in[android-developers] Re: How to draw ...
FromSent OnAttachments
battlecryApr 25, 2008 4:20 am 
volApr 25, 2008 5:59 am 
Diego PinoApr 26, 2008 3:55 am 
Subject:[android-developers] Re: How to draw Bitmap outside of onDraw()
From:vol (
Date:Apr 25, 2008 5:59:18 am

The canvas passed in onDraw is used for drawing to the screen, so you shouldn't store it. You can create your own canvas from your own Bitmap outside of onDraw easily.

private Bitmap mBitmap; private Canvas mCanvas; private Paint mPaint = new Paint();

private void createSurface() { Bitmap bmp = Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB8888); Canvas c = new Canvas(bmp); mBitmap = bmp; mCanvas = c; mPaint.setColor(0xffff0000); }

private void drawLine(float x1, float y1, float x2, float y2, Paint p) { mCanvas.drawLine(x1,y1,x2,y2,p); }

Please note that the Canvas can only draw to bitmaps that are Mutable.

battlecry wrote:


I want use canvas outside of the onDraw() method, I code this way:

Canvas mCanvas;

protected void onDraw(Canvas canvas) { mCanvas = canvas; }

private void drawSth(){ mCanvas.drawRect(0,0,100,100,mPaint); }

but it seems useless, please tell me how to draw sth outside of onDraw() method?