简体   繁体   中英

off screen drawing in android

is there off screen drawing possible 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.

ApiDemos/Graphics检查FingerPaint应用程序

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM