开发者

off screen drawing in android

is there off screen drawing poss开发者_高级运维ible in android like a imageContext in objective C. if it is kindly tell me the link or some kind of hint.

thanks a lot.


I believe you are looking for the Canvas object. This doesn't have to be on the screen when you draw on it (lines, shapes, bitmaps, etc.).

You'll first want to create a Bitmap to draw on.


Check out the FingerPaint application in ApiDemos/Graphics


Ii is possible to draw off screen by creating a canvas, assign it to a mutable bitmap and doing all drawing with canvas method, like this:

Canvas c = new Canvas();
Bitmap bmp = BitmapFactory.decodeResource(this, R.drawable.mybasebmp); // this is NOT MUTABLE!!
Bitmap bmpm = bmp.copy(bmp.getConfig(), true); // create a MUTABLE copy to draw on it
Bitmap bmpt = BitmapFactory.decodeResource(this, R.drawable.mytilebmp); // this is my tile
c.setBitmap(bmp);
Rect r = Rect(100,100,149, 149); // scaled to 50x50 pix to draw at position 100,100 in mybasebmp
c.drawBitmap(bmpt, null, r, null); // put a tile at 100,100
r.set(150,170, 150+50-1, 170+50-1); 
c.drawBitmap(bmpt, null,r, null); // put a tile at 150,170

// assign my drawn bitmap to an imageview to show it
ImageView iv = (ImageView) findViewById(R.id.myimageview);
iv.setImageBitmap(bmpm);

We use a canvas to do all the drawing in a mutable BMP and then we put that BMP in a viewable container like an imageview.

Hope it helps someone, I couldn't find any suitable tutorial to do this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜