cm.postConcat(tmp); tmp.setYUV2RGB(); cm.postConcat(tmp);
cm.postConcat(tmp); tmp.setYUV2RGB(); cm.postConcat(tmp);
cm.postConcat(tmp); tmp.setYUV2RGB(); cm.postConcat(tmp);
public static Bitmap handleImageEffect(Bitmap bm, float lum) { Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); ColorMatrix lumMatrix = new ColorMatrix(); lumMatrix.setScale(lum, lum, lum, 1); ColorMatrix imageMatrix = new ColorMatrix(); imageMatrix.postConcat(lumMatrix); paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix)); canvas.drawBitmap(bm, 0, 0, paint); return bmp; }
public static void adjustHue(ColorMatrix cm, float value) { value = cleanValue(value, 180f) / 180f * (float) Math.PI; if (value == 0) { return; } float cosVal = (float) Math.cos(value); float sinVal = (float) Math.sin(value); float lumR = 0.213f; float lumG = 0.715f; float lumB = 0.072f; float[] mat = new float[] { lumR + cosVal * (1 - lumR) + sinVal * (-lumR), lumG + cosVal * (-lumG) + sinVal * (-lumG), lumB + cosVal * (-lumB) + sinVal * (1 - lumB), 0, 0, lumR + cosVal * (-lumR) + sinVal * (0.143f), lumG + cosVal * (1 - lumG) + sinVal * (0.140f), lumB + cosVal * (-lumB) + sinVal * (-0.283f), 0, 0, lumR + cosVal * (-lumR) + sinVal * (-(1 - lumR)), lumG + cosVal * (-lumG) + sinVal * (lumG), lumB + cosVal * (1 - lumB) + sinVal * (lumB), 0, 0, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 0f, 1f}; cm.postConcat(new ColorMatrix(mat)); }
public static void adjustHue(ColorMatrix cm, float value) { value = cleanValue(value, 180f) / 180f * (float) Math.PI; if (value == 0) { return; } float cosVal = (float) Math.cos(value); float sinVal = (float) Math.sin(value); float lumR = 0.213f; float lumG = 0.715f; float lumB = 0.072f; float[] mat = new float[] { lumR + cosVal * (1 - lumR) + sinVal * (-lumR), lumG + cosVal * (-lumG) + sinVal * (-lumG), lumB + cosVal * (-lumB) + sinVal * (1 - lumB), 0, 0, lumR + cosVal * (-lumR) + sinVal * (0.143f), lumG + cosVal * (1 - lumG) + sinVal * (0.140f), lumB + cosVal * (-lumB) + sinVal * (-0.283f), 0, 0, lumR + cosVal * (-lumR) + sinVal * (-(1 - lumR)), lumG + cosVal * (-lumG) + sinVal * (lumG), lumB + cosVal * (1 - lumB) + sinVal * (lumB), 0, 0, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 0f, 1f}; cm.postConcat(new ColorMatrix(mat)); }
public static void adjustLightness(ColorMatrix cm, float value) { value = cleanValue(value, 100); if (value == 0) { return; } float[] mat = new float[] { 1,0,0,0,value, 0,1,0,0,value, 0,0,1,0,value, 0,0,0,1,0, 0,0,0,0,1 }; cm.postConcat(new ColorMatrix(mat)); } //Helper method protected static float cleanValue(float p_val, float p_limit) { return Math.min(p_limit, Math.max(-p_limit, p_val)); }
float invertMX[] = { -1.0f, 0.0f, 0.0f, 0.0f, 255f, 0.0f, -1.0f, 0.0f, 0.0f, 255f, 0.0f, 0.0f, -1.0f, 0.0f, 255f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }; ColorMatrix saturationZero = new ColorMatrix(); saturationZero.setSaturation(0); ColorMatrix finalCM = new ColorMatrix(saturationZero); ColorMatrix invertCM = new ColorMatrix(invertMX); finalCM.postConcat(invertCM); ColorMatrixColorFilter filter = new ColorMatrixColorFilter(finalCM); colorBMPPaint.setColorFilter(filter);
0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 0f, 1f }; cm.postConcat(new ColorMatrix(mat));
ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.setSaturation(0); float m = 255f; float t = -255*1.2f; ColorMatrix threshold = new ColorMatrix(new float[] { m, 0, 0, 1, t, 0, m, 0, 1, t, 0, 0, m, 1, t, 0, 0, 0, 1, 0 }); // Convert to grayscale, then scale and clamp colorMatrix.postConcat(threshold); ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix); imageView.setColorFilter(filter);
Drawable bgDrawable = button.getBackground(); ColorMatrix cmDesat = new ColorMatrix(); cmDesat.setSaturation( 0 ); ColorMatrix cm = new ColorMatrix(); cm.set( new float[]{ r, 0, 0, 0, 0, 0, g, 0, 0, 0, 0, 0, b, 0, 0, 0, 0, 0, 1, 0 } ); cmDesat.postConcat( cm ); bgDrawable.setColorFilter( new ColorMatrixColorFilter( cmDesat ) );
imageMatrix.postConcat(hueMatrix); imageMatrix.postConcat(saturationMatrix); imageMatrix.postConcat(lumMatrix);
private int rotateColor(int color, float rad) { float deg = rad * 180 / 3.1415927f; int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); ColorMatrix cm = new ColorMatrix(); ColorMatrix tmp = new ColorMatrix(); cm.setRGB2YUV(); tmp.setRotate(0, deg); cm.postConcat(tmp); tmp.setYUV2RGB(); cm.postConcat(tmp); final float[] a = cm.getArray(); int ir = floatToByte(a[0] * r + a[1] * g + a[2] * b); int ig = floatToByte(a[5] * r + a[6] * g + a[7] * b); int ib = floatToByte(a[10] * r + a[11] * g + a[12] * b); return Color.argb(Color.alpha(color), pinToByte(ir), pinToByte(ig), pinToByte(ib)); }
private int rotateColor(int color, float rad) { float deg = rad * 180 / 3.1415927f; int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); ColorMatrix cm = new ColorMatrix(); ColorMatrix tmp = new ColorMatrix(); cm.setRGB2YUV(); tmp.setRotate(0, deg); cm.postConcat(tmp); tmp.setYUV2RGB(); cm.postConcat(tmp); final float[] a = cm.getArray(); int ir = floatToByte(a[0] * r + a[1] * g + a[2] * b); int ig = floatToByte(a[5] * r + a[6] * g + a[7] * b); int ib = floatToByte(a[10] * r + a[11] * g + a[12] * b); return Color.argb(Color.alpha(color), pinToByte(ir), pinToByte(ig), pinToByte(ib)); }
public static Drawable getImageFiltered(Context context, int res, int color) { // load image: Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), res); BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap); // create matrix to convert to greyscale: ColorMatrix greyscaleMatrix = new ColorMatrix(); greyscaleMatrix.setSaturation(0); // create matrix to colorize and apply transluceny: ColorMatrix colorizeMatrix = new ColorMatrix(); color = context.getResources().getColor(color); colorizeMatrix.setScale(Color.red(color) / 255.0f, Color.green(color) / 255.0f, Color.blue(color) / 255.0f, Color.alpha(color) / 255.0f); // <- try setting this to 1.0f for no translucency // concatenate the two matrices and create a ColorMatrixColorFilter from the result: greyscaleMatrix.postConcat(colorizeMatrix); ColorMatrixColorFilter filter = new ColorMatrixColorFilter(greyscaleMatrix); // apply the filter: drawable.setColorFilter(filter); return drawable; }
public void setColor(int color) { if (mPaint == null) { mPaint = new Paint(Paint.FILTER_BITMAP_FLAG); } if (color != 0) { ColorMatrix m1 = new ColorMatrix(); m1.setSaturation(0); ColorMatrix m2 = new ColorMatrix(); setColorScale(color, m2); m1.postConcat(m2); if (Utilities.ATLEAST_LOLLIPOP) { animateFilterTo(m1.getArray()); } else { mPaint.setColorFilter(new ColorMatrixColorFilter(m1)); invalidate(); } } else { if (!Utilities.ATLEAST_LOLLIPOP || mCurrentFilter == null) { mPaint.setColorFilter(null); invalidate(); } else { animateFilterTo(new ColorMatrix().getArray()); } } }
public void setColor(int color) { if (mPaint == null) { mPaint = new Paint(Paint.FILTER_BITMAP_FLAG); } if (color != 0) { ColorMatrix m1 = new ColorMatrix(); m1.setSaturation(0); ColorMatrix m2 = new ColorMatrix(); setColorScale(color, m2); m1.postConcat(m2); if (Utilities.ATLEAST_LOLLIPOP) { animateFilterTo(m1.getArray()); } else { mPaint.setColorFilter(new ColorMatrixColorFilter(m1)); invalidate(); } } else { if (!Utilities.ATLEAST_LOLLIPOP || mCurrentFilter == null) { mPaint.setColorFilter(null); invalidate(); } else { animateFilterTo(new ColorMatrix().getArray()); } } }
public void setColor(int color) { if (mPaint == null) { mPaint = new Paint(Paint.FILTER_BITMAP_FLAG); } if (color != 0) { ColorMatrix m1 = new ColorMatrix(); m1.setSaturation(0); ColorMatrix m2 = new ColorMatrix(); ThemeUtils.setColorScaleOnMatrix(color, m2); m1.postConcat(m2); animateFilterTo(m1.getArray()); } else { if (mCurrentFilter == null) { mPaint.setColorFilter(null); invalidate(); } else { animateFilterTo(new ColorMatrix().getArray()); } } }
public void setColor(int color) { if (mPaint == null) { mPaint = new Paint(Paint.FILTER_BITMAP_FLAG); } if (color != 0) { ColorMatrix m1 = new ColorMatrix(); m1.setSaturation(0); ColorMatrix m2 = new ColorMatrix(); setColorScale(color, m2); m1.postConcat(m2); if (Utilities.ATLEAST_LOLLIPOP) { animateFilterTo(m1.getArray()); } else { mPaint.setColorFilter(new ColorMatrixColorFilter(m1)); invalidate(); } } else { if (!Utilities.ATLEAST_LOLLIPOP || mCurrentFilter == null) { mPaint.setColorFilter(null); invalidate(); } else { animateFilterTo(new ColorMatrix().getArray()); } } }
private void createFilters() { ColorMatrix grayscaleMatrix = new ColorMatrix(); grayscaleMatrix.setSaturation(0); grayscaleFilter = new ColorMatrixColorFilter(grayscaleMatrix); ColorMatrix grayscaleInvertMatrix = new ColorMatrix(); grayscaleInvertMatrix.setSaturation(0); grayscaleInvertMatrix.postConcat(new ColorMatrix(INVERT_MATRIX)); grayscaleInvertFilter = new ColorMatrixColorFilter(grayscaleInvertMatrix); invertFilter = new ColorMatrixColorFilter(INVERT_MATRIX); }