I have LinearLayout containing some views. Is it possible to do so that everything inside LinearLayout are drawn in grayscale color mode?
Asked
Active
Viewed 419 times
1 Answers
0
you need to extends LinearLayout and override dispatchDraw method.
then create a Bitmap with the size of LinearLayout and a canvas. and call super.dispatchDraw with new canvas as parameter. after that you draw the bitmap on the original Canvas with a paint setting a ColorFilter.
here's the example:
private Bitmap mBitmap;
private Canvas mCanvas;
private Paint mPaint;
public {Constructor}{
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);
ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
mPaint.setColorFilter(colorFilter);
}
@Override
public void onSizeChanged(int w, int h, in oldw, int oldh){
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvas = new Camvas(mBitmap);
}
@Override
public void dispatchDraw(Canvas canvas){
super.dispatchDraw(mCanvas);
canvas.drawBitmap(mBitmap, 0, 0, mPaint);
}

7heaven
- 797
- 7
- 16