Black and white,
The implementation of the activity
SetContentView () sets the following code, either based on the base Activity class or on a single business module
Paint mPaint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0F);
mPaint.setColorFilter(new ColorMatrixColorFilter(cm));
getWindow().getDecorView().setLayerType(View.LAYER_TYPE_SOFTWARE, mPaint);
Copy the code
ImageView implementation or XML root layout implementation
Kotlin version
val mPaint = Paint()
val cm = ColorMatrix()
cm.setSaturation(0F)
mPaint.colorFilter = ColorMatrixColorFilter(cm)
xxxid.setLayerType(View.LAYER_TYPE_SOFTWARE, mPaint)
Copy the code
The exploration of black and white color
Plan a
val mPaint = Paint()
val cm = ColorMatrix()
cm.setSaturation(0F)
mPaint.colorFilter = ColorMatrixColorFilter(cm)
xxxId.setLayerType(View.LAYER_TYPE_SOFTWARE, mPaint)
Copy the code
Scheme 2
val mPaint = Paint()
val cm = ColorMatrix()
cm.setYUV2RGB()
mPaint.colorFilter = ColorMatrixColorFilter(cm)
xxxId.setLayerType(View.LAYER_TYPE_SOFTWARE, mPaint)
Copy the code
Plan 3
val mPaint = Paint()
val cm = ColorMatrix()
cm.setRGB2YUV()
mPaint.colorFilter = ColorMatrixColorFilter(cm)
xxxId.setLayerType(View.LAYER_TYPE_SOFTWARE, mPaint)
Copy the code
Plan 4
val mPaint = Paint()
val cm = ColorMatrix()
val array: FloatArray = cm.array
array[0] = -1F
array[3] = 1F
array[4] = 1F
array[6] = -1F
array[8] = 1F
array[9] = 1F
array[12] = -1F
array[13] = 1F
array[14] = 1F
array[18] = 1F
mPaint.colorFilter = ColorMatrixColorFilter(cm)
xxxId.setLayerType(View.LAYER_TYPE_SOFTWARE, mPaint)
Copy the code
Plan 5
val mPaint = Paint() val cm = ColorMatrix() val array: FloatArray = cm. Array Array [0]= 1.5F array[1]= 1.5F array[2]= 1.5F array[4]= -1F array[5]= 1.5F array[6]= 1.5F array[7]= ColorFilter = 1.5F array[9]= -1F array[10]= 1.5F array[11]= 1.5F array[12]= 1.5F array[14]= -1F array[18]= 1F mPaint ColorMatrixColorFilter(cm) xxxId.setLayerType(View.LAYER_TYPE_SOFTWARE, mPaint)Copy the code