Bitmap sourceBitmap = BitmapFactory.decodeFile(imgPath); float[] colorTransform = { 0, 1f, 0, 0, 0, 0, 0, 0f, 0, 0, 0, 0, 0, 0f, 0, 0, 0, 0, 1f, 0}; ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.setSaturation(0f); //Remove Colour colorMatrix.set(colorTransform); //Apply the Red ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix); Paint paint = new Paint(); paint.setColorFilter(colorFilter); Display display = getWindowManager().getDefaultDisplay(); Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, (int)(display.getHeight() * 0.15), display.getWidth(), (int)(display.getHeight() * 0.75)); image.setImageBitmap(resultBitmap); Canvas canvas = new Canvas(resultBitmap); canvas.drawBitmap(resultBitmap, 0, 0, paint);
public PageWidget(Context context, String bookId, List<BookMixAToc.mixToc.Chapters> chaptersList, OnReadStateChangeListener listener) { super(context, bookId, chaptersList, listener); mPath0 = new Path(); mPath1 = new Path(); mMaxLength = (float) Math.hypot(mScreenWidth, mScreenHeight); mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); createDrawable(); ColorMatrix cm = new ColorMatrix();//设置颜色数组 float array[] = {0.55f, 0, 0, 0, 80.0f, 0, 0.55f, 0, 0, 80.0f, 0, 0, 0.55f, 0, 80.0f, 0, 0, 0, 0.2f, 0}; cm.set(array); mColorMatrixFilter = new ColorMatrixColorFilter(cm); mMatrix = new Matrix(); mTouch.x = 0.01f; // 不让x,y为0,否则在点计算时会有问题 mTouch.y = 0.01f; }
float[] colorTransform = { 0, 1f, 0, 0, 0, 0, 0, 0f, 0, 0, 0, 0, 0, 0f, 0, 0, 0, 0, 1f, 0}; ColorMatrix localColorMatrix = new ColorMatrix(); localColorMatrix.setSaturation(0.0F); //Remove Colour localColorMatrix.set(colorTransform); //Apply Red say
elements[10] = R; elements[11] = G; elements[12] = B + fraction; colorMatrix.set(elements); return colorMatrix;
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 ) );
private void init(Context context, Calendar calendar) { //In the Android 4.2 , LAYER_TYPE_SOFTWARE will cause some question int year = YearClass.get(context.getApplicationContext()); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1 || year < YearClass.CLASS_2013) { this.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } //View setScreen(context); createBitmaps(); //Set calendar , this object should be created after w,h was set. calendarFactory = new CalendarFactory(context, calendar, mWidth, mHeight); //Page effect mPath0 = new Path(); mPath1 = new Path(); createDrawable(); mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); ColorMatrix cm = new ColorMatrix(); float array[] = {0.55f, 0, 0, 0, 80.0f, 0, 0.55f, 0, 0, 80.0f, 0, 0, 0.55f, 0, 80.0f, 0, 0, 0, 0.2f, 0}; cm.set(array); mColorMatrixFilter = new ColorMatrixColorFilter(cm); mMatrix = new Matrix(); mScroller = new Scroller(getContext()); mTouch.x = 0.01f; // 不让x,y为0,否则在点计算时会有问题 mTouch.y = 0.01f; //Set today text calendarFactory.onDraw(mCurrentPageCanvas); }
private static void setContrastTranslateOnly(ColorMatrix cm, float contrast) { float scale = contrast + 1.f; float translate = (-.5f * scale + .5f) * 255.f; cm.set(new float[] { 1, 0, 0, 0, translate, 0, 1, 0, 0, translate, 0, 0, 1, 0, translate, 0, 0, 0, 1, 0 }); }
private static void setContrast(ColorMatrix cm, float contrast) { float scale = contrast + 1.f; float translate = (-.5f * scale + .5f) * 255.f; cm.set(new float[] { scale, 0, 0, 0, translate, 0, scale, 0, 0, translate, 0, 0, scale, 0, translate, 0, 0, 0, 1, 0 }); }
private static void setContrastScaleOnly(ColorMatrix cm, float contrast) { float scale = contrast + 1.f; float translate = (-.5f * scale + .5f) * 255.f; cm.set(new float[] { scale, 0, 0, 0, 0, 0, scale, 0, 0, 0, 0, 0, scale, 0, 0, 0, 0, 0, 1, 0 }); }
private static void setTranslate(ColorMatrix cm, float dr, float dg, float db, float da) { cm.set(new float[] { 2, 0, 0, 0, dr, 0, 2, 0, 0, dg, 0, 0, 2, 0, db, 0, 0, 0, 1, da }); }
private static void setContrast(ColorMatrix cm, float contrast) { float scale = contrast + 1.f; float translate = (-.5f * scale + .5f) * 255.f; cm.set(new float[] { scale, 0, 0, 0, translate, 0, scale, 0, 0, translate, 0, 0, scale, 0, translate, 0, 0, 0, 1, 0 }); }
private static void setTranslate(ColorMatrix cm, float dr, float dg, float db, float da) { cm.set(new float[] { 2, 0, 0, 0, dr, 0, 2, 0, 0, dg, 0, 0, 2, 0, db, 0, 0, 0, 1, da }); }
private static void setContrastTranslateOnly(ColorMatrix cm, float contrast) { float scale = contrast + 1.f; float translate = (-.5f * scale + .5f) * 255.f; cm.set(new float[] { 1, 0, 0, 0, translate, 0, 1, 0, 0, translate, 0, 0, 1, 0, translate, 0, 0, 0, 1, 0 }); }
private static void setContrastScaleOnly(ColorMatrix cm, float contrast) { float scale = contrast + 1.f; float translate = (-.5f * scale + .5f) * 255.f; cm.set(new float[] { scale, 0, 0, 0, 0, 0, scale, 0, 0, 0, 0, 0, scale, 0, 0, 0, 0, 0, 1, 0 }); }
Bitmap img = BitmapFactory.decodeResource(this.getResources(), drawable.testimage); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); float a = 77f; float b = 151f; float c = 28f; float t = 120 * -256f; cm.set(new float[] { a, b, c, 0, t, a, b, c, 0, t, a, b, c, 0, t, 0, 0, 0, 1, 0 }); paint.setColorFilter(new ColorMatrixColorFilter(cm)); canvas.drawBitmap(img, 0, 0, paint);
Random rand = new Random(); int r = rand.nextInt(256); int g = rand.nextInt(256); int b = rand.nextInt(256); ColorMatrix cm = new ColorMatrix(); cm.set(new float[] { 1, 0, 0, 0, r, 0, 1, 0, 0, g, 0, 0, 1, 0, b, 0, 0, 0, 1, 0 }); // last line is antialias paint.setColorFilter(new ColorMatrixColorFilter(cm)); canvas.drawBitmap(myBitmap, toX, toY, paint);
ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.set(new float[] { RED/255.0f, 0, 0, 0, 0, 0, GREEN/255.0f, 0, 0, 0 0, 0, BLUE/255.0f, 0, 0, 0, 0, 0, 1, 0}); imageView.setColorFilter(new ColorMatrixColorFilter(colorMatrix);
private void setColorMatrix(float[] matrix) { mColorMatrix.set(matrix); mColorFilter = new ColorMatrixColorFilter(mColorMatrix); }
public static Bitmap getFilterBitmap(Bitmap bitmap, int filter) { Bitmap bmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.set(getFilter(filter)); paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix)); canvas.drawBitmap(bitmap, 0, 0, paint); return bmp; }
void changeBrightness(int value) { float brightness = value / 2; mColorMatrix.reset(); mColorMatrix.set(new float[]{ 1, 0, 0, 0, brightness, 0, 1, 0, 0, brightness, 0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 }); mAdjustPaint.setColorFilter(new ColorMatrixColorFilter(mColorMatrix)); getViewState().onImageAdjusted(mAdjustPaint); }