The method below works, but it unfortunately, this method involves creating a bitmap the size of the entire screen - not just the area that is drawn to. If I use this to draw UI elements, it is redrawn for each UI element. Can this be done more efficiently?
@Override
protected void onDraw(Canvas canvas) {
//TODO: Reduce the burden from multiple drawing
Bitmap bitmap=Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Config.ARGB_8888);
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);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…