Override onDraw to change how the drawing occurs (Android)
Posted
by Casebash
on Stack Overflow
See other posts from Stack Overflow
or by Casebash
Published on 2010-05-04T07:33:58Z
Indexed on
2010/05/04
7:38 UTC
Read the original article
Hit count: 191
android
I want to change how my UI elements display, so I am overriding onDraw
. The following code allows me to change a View
to be drawn using PorterDuff.Mode.DARKEN
. Unfortunately, this method involves creating a bitmap the size of the entire screen, then drawing to it then drawing this large bitmap the main screen again, for each UI element. This isn't at all efficient. Is it possible to achieve this in a more effecient way?
@Override
protected void onDraw(Canvas canvas) {
//TODO: Reduce the burden from multiple drawing
Bitmap bitmap=Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Config.ARGB_8888);
Log.e("tmp",canvas.getClipBounds().toString());
Canvas offscreen=new Canvas(bitmap);
super.onDraw(offscreen);
//Then draw onscreen
Paint p=new Paint();
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DARKEN));
canvas.drawBitmap(bitmap, 0, 0, p);
}
© Stack Overflow or respective owner