use of android.graphics.ColorMatrix in project android_frameworks_base by ResurrectionRemix.
the class ImageHelper method toGrayscale.
private static Bitmap toGrayscale(Bitmap bmpOriginal) {
int width, height;
height = bmpOriginal.getHeight();
width = bmpOriginal.getWidth();
Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmpGrayscale);
Paint paint = new Paint();
paint.setAntiAlias(true);
ColorMatrix cm = new ColorMatrix();
final Rect rect = new Rect(0, 0, width, height);
cm.setSaturation(0);
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
paint.setColorFilter(f);
c.drawBitmap(bmpOriginal, rect, rect, paint);
return bmpGrayscale;
}
use of android.graphics.ColorMatrix in project android_frameworks_base by ResurrectionRemix.
the class ColorHelper method getColorFilter.
public static ColorMatrixColorFilter getColorFilter(int color) {
float r = Color.red(color) / 255f;
float g = Color.green(color) / 255f;
float b = Color.blue(color) / 255f;
ColorMatrix cm = new ColorMatrix(new float[] { r, 0, 0, 0, 0, 0, g, 0, 0, 0, 0, 0, b, 0, 0, 0, 0, 0, 1, 0 });
ColorMatrixColorFilter cf = new ColorMatrixColorFilter(cm);
return cf;
}
use of android.graphics.ColorMatrix in project android_frameworks_base by ResurrectionRemix.
the class ColorHelper method toGrayscale.
private static Bitmap toGrayscale(Bitmap bmpOriginal) {
int width, height;
height = bmpOriginal.getHeight();
width = bmpOriginal.getWidth();
Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmpGrayscale);
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
paint.setColorFilter(f);
c.drawBitmap(bmpOriginal, 0, 0, paint);
return bmpGrayscale;
}
use of android.graphics.ColorMatrix in project UltimateAndroid by cymcsg.
the class SquareProgressBar method setImageGrayscale.
/**
* You can set the image to b/w with this method. Works fine with the
* opacity.
*
* @param greyscale
* true if the grayscale should be activated.
* @since 1.2.0
*/
public void setImageGrayscale(boolean greyscale) {
this.greyscale = greyscale;
if (greyscale) {
ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(0);
imageView.setColorFilter(new ColorMatrixColorFilter(matrix));
} else {
imageView.setColorFilter(null);
}
}
use of android.graphics.ColorMatrix in project Lightning-Browser by anthonycr.
the class LightningView method setColorMode.
/**
* Sets the current rendering color of the WebView instance
* of the current LightningView. The for modes are normal
* rendering (0), inverted rendering (1), grayscale rendering (2),
* and inverted grayscale rendering (3)
*
* @param mode the integer mode to set as the rendering mode.
* see the numbers in documentation above for the
* values this method accepts.
*/
private void setColorMode(int mode) {
mInvertPage = false;
switch(mode) {
case 0:
mPaint.setColorFilter(null);
// setSoftwareRendering(); // Some devices get segfaults
// in the WebView with Hardware Acceleration enabled,
// the only fix is to disable hardware rendering
setNormalRendering();
mInvertPage = false;
break;
case 1:
ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter(sNegativeColorArray);
mPaint.setColorFilter(filterInvert);
setHardwareRendering();
mInvertPage = true;
break;
case 2:
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
ColorMatrixColorFilter filterGray = new ColorMatrixColorFilter(cm);
mPaint.setColorFilter(filterGray);
setHardwareRendering();
break;
case 3:
ColorMatrix matrix = new ColorMatrix();
matrix.set(sNegativeColorArray);
ColorMatrix matrixGray = new ColorMatrix();
matrixGray.setSaturation(0);
ColorMatrix concat = new ColorMatrix();
concat.setConcat(matrix, matrixGray);
ColorMatrixColorFilter filterInvertGray = new ColorMatrixColorFilter(concat);
mPaint.setColorFilter(filterInvertGray);
setHardwareRendering();
mInvertPage = true;
break;
case 4:
ColorMatrixColorFilter IncreaseHighContrast = new ColorMatrixColorFilter(sIncreaseContrastColorArray);
mPaint.setColorFilter(IncreaseHighContrast);
setHardwareRendering();
break;
}
}
Aggregations