android.graphics.ColorMatrix Java Examples

The following examples show how to use android.graphics.ColorMatrix. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DragView.java    From Trebuchet with GNU General Public License v3.0 7 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void animateFilterTo(float[] targetFilter) {
    float[] oldFilter = mCurrentFilter == null ? new ColorMatrix().getArray() : mCurrentFilter;
    mCurrentFilter = Arrays.copyOf(oldFilter, oldFilter.length);

    if (mFilterAnimator != null) {
        mFilterAnimator.cancel();
    }
    mFilterAnimator = ValueAnimator.ofObject(new FloatArrayEvaluator(mCurrentFilter),
            oldFilter, targetFilter);
    mFilterAnimator.setDuration(COLOR_CHANGE_DURATION);
    mFilterAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mPaint.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
            invalidate();
        }
    });
    mFilterAnimator.start();
}
 
Example #2
Source File: SimulationPageAnim.java    From FriendBook with GNU General Public License v3.0 6 votes vote down vote up
public SimulationPageAnim(int w, int h, View view, OnPageChangeListener listener) {
    super(w, h, view, 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[] = { 1, 0, 0, 0, 0,
            0, 1, 0, 0, 0,
            0, 0,1, 0, 0,
            0, 0, 0, 1, 0 };
    cm.set(array);
    mColorMatrixFilter = new ColorMatrixColorFilter(cm);
    mMatrix = new Matrix();

    mTouchX = 0.01f; // 不让x,y为0,否则在点计算时会有问题
    mTouchY = 0.01f;
}
 
Example #3
Source File: HaloFragment.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override protected ColorFilter getOnlineColorFilter() {
    if (haloModel == null || mView == null) {
        return null;
    }

    View colorOverlayView = mView.findViewById(R.id.color_overlay);
    if (colorOverlayView == null) {
        return null;
    }

    boolean applyFilter = haloModel.isOnline() && isVisible();
    colorOverlayView.setVisibility(applyFilter ? View.VISIBLE : View.GONE);

    if(applyFilter) {
        float [] colorHSV = new float[]{ haloModel.getHue(), (haloModel.getSaturation() / 100f), 1f};
        colorOverlayView.setBackgroundColor(Color.HSVToColor(25, colorHSV));

        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0f);
        return new ColorMatrixColorFilter(cm);
    }

    return null;
}
 
Example #4
Source File: HueFallbackFragment.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override
public void updateBackground(boolean isConnected) {
    try {
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0f);
        final ColorFilter filter = new ColorMatrixColorFilter(cm);
        final View bgView = ImageManager.getWallpaperView();
        if (bgView != null) {
            final Drawable bgDrawable = bgView.getBackground();
            if (bgDrawable != null) {
                bgDrawable.setColorFilter(filter);
            }
        }
    }catch (Exception e){
        logger.error("Can't change background color filter: {}", e);
    }
}
 
Example #5
Source File: GreyScaleTransformation.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override
public Bitmap transform(@NonNull Bitmap source) {

    int width = source.getWidth();
    int height = source.getHeight();

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    ColorMatrix saturation = new ColorMatrix();
    saturation.setSaturation(0f);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(saturation));
    canvas.drawBitmap(source, 0, 0, paint);

    if (bitmap != source && !source.isRecycled()) {
        source.recycle();
    }

    return bitmap;
}
 
Example #6
Source File: BitmapManipulator.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
static Bitmap grayScaleBitmap(Bitmap bitmap)
{
    if (bitmap == null)
        return null;

    Bitmap monochromeBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(),
            bitmap.getConfig());
    Canvas canvas = new Canvas(monochromeBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0.0f);
    paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    Matrix matrix = new Matrix();
    canvas.drawBitmap(bitmap, matrix, paint);

    return monochromeBitmap;
}
 
Example #7
Source File: SimulationPageAnim.java    From a with GNU General Public License v3.0 6 votes vote down vote up
public SimulationPageAnim(int w, int h, View view, OnPageChangeListener listener) {
    super(w, h, view, 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 = {1, 0, 0, 0, 0,
            0, 1, 0, 0, 0,
            0, 0, 1, 0, 0,
            0, 0, 0, 1, 0};
    cm.set(array);
    mColorMatrixFilter = new ColorMatrixColorFilter(cm);
    mMatrix = new Matrix();

    mTouchX = 0.01f; // 不让x,y为0,否则在点计算时会有问题
    mTouchY = 0.01f;
    blurBackImage = MApplication.getConfigPreferences().getBoolean("blurSimBack", false);
}
 
Example #8
Source File: GrayscaleTransformation.java    From glide-transformations with Apache License 2.0 6 votes vote down vote up
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
                           @NonNull Bitmap toTransform, int outWidth, int outHeight) {
  int width = toTransform.getWidth();
  int height = toTransform.getHeight();

  Bitmap.Config config =
      toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = pool.get(width, height, config);

  setCanvasBitmapDensity(toTransform, bitmap);

  Canvas canvas = new Canvas(bitmap);
  ColorMatrix saturation = new ColorMatrix();
  saturation.setSaturation(0f);
  Paint paint = new Paint();
  paint.setColorFilter(new ColorMatrixColorFilter(saturation));
  canvas.drawBitmap(toTransform, 0, 0, paint);

  return bitmap;
}
 
Example #9
Source File: ArcusProductFragment.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
/**
 * convert the current screen color to grey
 * @param apply apply grey scale or not
 */
private void applyGreyScale(final boolean apply){

    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0f);
    final ColorFilter filter = new ColorMatrixColorFilter(cm);

    if (apply) {
        if (deviceImage != null) this.deviceImage.setColorFilter(filter);
        if (this.leftNav != null) this.leftNav.setColorFilter(null);
        if (this.rightNav != null) this.rightNav.setColorFilter(null);
        if (this.bottomView != null && !isBottomViewAlerting) this.bottomView.getBackground().setColorFilter(filter);
    } else {
        if (deviceImage != null) this.deviceImage.setColorFilter(null);
        if (this.leftNav != null) this.leftNav.setColorFilter(null);
        if (this.rightNav != null) this.rightNav.setColorFilter(null);
        if (this.bottomView != null && !isBottomViewAlerting) this.bottomView.getBackground().setColorFilter(null);
    }
}
 
Example #10
Source File: BaseCaptureActivity.java    From ViewCapture with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Bitmap process(Bitmap raw) {
    //Gray level
    int width = raw.getWidth();
    int height = raw.getHeight();
    Bitmap bmpGray = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    Canvas c = new Canvas(bmpGray);
    Paint paint = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(raw, 0, 0, paint);
    return bmpGray;
}
 
Example #11
Source File: ImageUtils.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 6 votes vote down vote up
/**
 * Returns a gray scale version of the input bitmap.
 *
 * @param bmpOriginal the image to convert.
 * @return gray scale version.
 */
static Bitmap toGrayScale(Bitmap bmpOriginal) {
    int         height       = bmpOriginal.getHeight();
    int         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;
}
 
Example #12
Source File: GrayscaleTransformation.java    From picasso-transformations with Apache License 2.0 6 votes vote down vote up
@Override public Bitmap transform(Bitmap source) {

    int width = source.getWidth();
    int height = source.getHeight();

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    ColorMatrix saturation = new ColorMatrix();
    saturation.setSaturation(0f);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(saturation));
    canvas.drawBitmap(source, 0, 0, paint);
    source.recycle();

    return bitmap;
  }
 
Example #13
Source File: ImageUtils.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 6 votes vote down vote up
/**
 * Adjusts the brightness and contrast in the input bitmap.
 *
 * @param bitmap     input bitmap.
 * @param contrast   the new contrast value.
 * @param brightness the new brightness value.
 * @return bitmap with contrast and brightness changes.
 */
static Bitmap contrastAndBrightnessController(Bitmap bitmap, float contrast, float brightness) {

    ColorMatrix cmatrix = new ColorMatrix(new float[]
            {
                    contrast, 0, 0, 0, brightness,
                    0, contrast, 0, 0, brightness,
                    0, 0, contrast, 0, brightness,
                    0, 0, 0, 1, 0
            });

    Bitmap ret    = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    Canvas canvas = new Canvas(ret);
    Paint  paint  = new Paint();

    paint.setColorFilter(new ColorMatrixColorFilter(cmatrix));
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return ret;
}
 
Example #14
Source File: BitmapUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 饱和度处理
 *
 * @param bitmap          原图
 * @param saturationValue 新的饱和度值
 * @return 改变了饱和度值之后的图片
 */
public static Bitmap saturation(Bitmap bitmap, int saturationValue) {
    // 计算出符合要求的饱和度值
    float newSaturationValue = saturationValue * 1.0F / 127;
    // 创建一个颜色矩阵
    ColorMatrix saturationColorMatrix = new ColorMatrix();
    // 设置饱和度值
    saturationColorMatrix.setSaturation(newSaturationValue);
    // 创建一个画笔并设置其颜色过滤器
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(saturationColorMatrix));
    // 创建一个新的图片并创建画布
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 将原图使用给定的画笔画到画布上
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}
 
Example #15
Source File: SepiaToneTiles.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void addOverlays(){
    super.addOverlays();
    final ColorMatrix matrixA = new ColorMatrix();
    // making image B&W
    matrixA.setSaturation(0);

    final ColorMatrix matrixB = new ColorMatrix();
    // applying scales for RGB color values
    matrixB.setScale(1f, .95f, .82f, 1.0f);
    matrixA.setConcat(matrixB, matrixA);

    final ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrixA);

    mMapView.getOverlayManager().getTilesOverlay().setColorFilter(filter);

}
 
Example #16
Source File: DragView.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
private void animateFilterTo(float[] targetFilter) {
    float[] oldFilter = mCurrentFilter == null ? new ColorMatrix().getArray() : mCurrentFilter;
    mCurrentFilter = Arrays.copyOf(oldFilter, oldFilter.length);

    if (mFilterAnimator != null) {
        mFilterAnimator.cancel();
    }
    mFilterAnimator = ValueAnimator.ofObject(new FloatArrayEvaluator(mCurrentFilter),
            oldFilter, targetFilter);
    mFilterAnimator.setDuration(COLOR_CHANGE_DURATION);
    mFilterAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mPaint.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
            invalidate();
        }
    });
    mFilterAnimator.start();
}
 
Example #17
Source File: ImageUtils.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
 * 调整照片的色调,饱和度,亮度
 * MID_VALUE = 177; // 进度条的中间值
 * @param bm 原图
 * @param hue 色调 = (进度条进度 - MID_VALUE) * 1.0F / MIN_VALUE * 180
 * @param saturation 饱和度 = 进度条进度 * 1.0F / MIN_VALUE;
 * @param lum 亮度 = 进度条进度 * 1.0F / MIN_VALUE;
 * @return 调整后的图片
 */
public static Bitmap handleImageEffect(Bitmap bm, int hue, int saturation, int lum) {
    Bitmap bitmap = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    ColorMatrix hueMatrix = new ColorMatrix();
    hueMatrix.setRotate(0,hue);
    hueMatrix.setRotate(1,hue);
    hueMatrix.setRotate(2, hue);

    ColorMatrix saturationMatrix = new ColorMatrix();
    saturationMatrix.setSaturation(saturation);

    ColorMatrix lumMatrix = new ColorMatrix();
    lumMatrix.setScale(lum,lum,lum,1);

    ColorMatrix imageMatrix = new ColorMatrix();
    imageMatrix.postConcat(hueMatrix);
    imageMatrix.postConcat(saturationMatrix);
    imageMatrix.postConcat(lumMatrix);

    paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix));
    canvas.drawBitmap(bm,0,0,paint);
    return bitmap;
}
 
Example #18
Source File: ColorPickerDialog.java    From AndroidDrawing with MIT License 6 votes vote down vote up
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));
}
 
Example #19
Source File: XBitmapUtils.java    From XFrame with Apache License 2.0 6 votes vote down vote up
/**
 * 亮度处理
 *
 * @param bitmap   原图
 * @param lumValue 新的亮度值
 * @return 改变了亮度值之后的图片
 */
public static Bitmap lum(Bitmap bitmap, int lumValue) {
    // 计算出符合要求的亮度值
    float newlumValue = lumValue * 1.0F / 127;
    // 创建一个颜色矩阵
    ColorMatrix lumColorMatrix = new ColorMatrix();
    // 设置亮度值
    lumColorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
    // 创建一个画笔并设置其颜色过滤器
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(lumColorMatrix));
    // 创建一个新的图片并创建画布
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 将原图使用给定的画笔画到画布上
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}
 
Example #20
Source File: XBitmapUtils.java    From XFrame with Apache License 2.0 6 votes vote down vote up
/**
 * 色相处理
 *
 * @param bitmap   原图
 * @param hueValue 新的色相值
 * @return 改变了色相值之后的图片
 */
public static Bitmap hue(Bitmap bitmap, int hueValue) {
    // 计算出符合要求的色相值
    float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;
    // 创建一个颜色矩阵
    ColorMatrix hueColorMatrix = new ColorMatrix();
    // 控制让红色区在色轮上旋转的角度
    hueColorMatrix.setRotate(0, newHueValue);
    // 控制让绿红色区在色轮上旋转的角度
    hueColorMatrix.setRotate(1, newHueValue);
    // 控制让蓝色区在色轮上旋转的角度
    hueColorMatrix.setRotate(2, newHueValue);
    // 创建一个画笔并设置其颜色过滤器
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(hueColorMatrix));
    // 创建一个新的图片并创建画布
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 将原图使用给定的画笔画到画布上
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}
 
Example #21
Source File: SimulationPageAnim.java    From NovelReader with MIT License 6 votes vote down vote up
public SimulationPageAnim(int w, int h, View view, OnPageChangeListener listener) {
    super(w, h, view, listener);
    mPath0 = new Path();
    mPath1 = new Path();
    mXORPath = new Path();
    mMaxLength = (float) Math.hypot(mScreenWidth, mScreenHeight);
    mPaint = new Paint();

    mPaint.setStyle(Paint.Style.FILL);

    createDrawable();

    ColorMatrix cm = new ColorMatrix();//设置颜色数组
    float array[] = {1, 0, 0, 0, 0,
            0, 1, 0, 0, 0,
            0, 0, 1, 0, 0,
            0, 0, 0, 1, 0};
    cm.set(array);
    mColorMatrixFilter = new ColorMatrixColorFilter(cm);
    mMatrix = new Matrix();

    mTouchX = 0.01f; // 不让x,y为0,否则在点计算时会有问题
    mTouchY = 0.01f;
}
 
Example #22
Source File: CoverFlowLayoutManger.java    From RecyclerCoverFlow with Apache License 2.0 6 votes vote down vote up
/**
     * 变化Item的灰度值
     * @param child 需要设置灰度值的Item
     * @param frame 位置信息
     */
    private void greyItem(View child, Rect frame) {
        float value = computeGreyScale(frame.left - mOffsetAll);
        ColorMatrix cm = new ColorMatrix(new float[]{
                value, 0, 0, 0, 120*(1-value),
                0, value, 0, 0, 120*(1-value),
                0, 0, value, 0, 120*(1-value),
                0, 0, 0, 1, 250*(1-value),
        });
//        cm.setSaturation(0.9f);

        // Create a paint object with color matrix
        Paint greyPaint = new Paint();
        greyPaint.setColorFilter(new ColorMatrixColorFilter(cm));

        // Create a hardware layer with the grey paint
        child.setLayerType(View.LAYER_TYPE_HARDWARE, greyPaint);
        if (value >= 1) {
            // Remove the hardware layer
            child.setLayerType(View.LAYER_TYPE_NONE, null);
        }

    }
 
Example #23
Source File: ImageUtil.java    From XposedNavigationBar with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #24
Source File: ColorMatrixActivity.java    From android-graphics-demo with Apache License 2.0 6 votes vote down vote up
private ColorMatrix getBinaryColorMatrix() {
  ColorMatrix colorMatrix = new ColorMatrix();
  colorMatrix.setSaturation(0);

  float m = 255f;
  float t = -255*128f;
  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 threshold
  colorMatrix.postConcat(threshold);

  return colorMatrix;
}
 
Example #25
Source File: ColorHelper.java    From Noyze with Apache License 2.0 6 votes vote down vote up
/**
 * @param cm
 * @param value
 * @see http://groups.google.com/group/android-developers/browse_thread/thread/9e215c83c3819953
 * @see http://gskinner.com/blog/archives/2007/12/colormatrix_cla.html
 */
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));
}
 
Example #26
Source File: PageWidget.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public PageWidget(Context context) {
	super(context);

	// TODO Auto-generated constructor stub
	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;
	mTouch.y = 0.01f;
}
 
Example #27
Source File: ColorUtil.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
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));
}
 
Example #28
Source File: BlurBuilder.java    From Audinaut with GNU General Public License v3.0 6 votes vote down vote up
public static Bitmap changeBitmapContrastBrightness(Bitmap bmp, float contrast, float brightness)
{
    ColorMatrix cm = new ColorMatrix(new float[]
            {
                contrast, 0, 0, 0, brightness,
                0, contrast, 0, 0, brightness,
                0, 0, contrast, 0, brightness,
                0, 0, 0, 1, 0
            });

    Bitmap ret = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());

    Canvas canvas = new Canvas(ret);

    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(cm));
    canvas.drawBitmap(bmp, 0, 0, paint);

    return ret;
}
 
Example #29
Source File: IosButton.java    From HumanBody with Apache License 2.0 6 votes vote down vote up
/**
 * 传入改变亮度前的bitmap,返回改变亮度后的bitmap
 * @author leibing
 * @createTime 2016/12/30
 * @lastModify 2016/12/30
 * @param srcBitmap
 * @return
 */
   @SuppressWarnings("deprecation")
public Drawable changeBrightnessBitmap(Bitmap srcBitmap){  
        Bitmap bmp = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(),    
               Config.ARGB_8888);    
       int brightness = 60 - 127;    
       ColorMatrix cMatrix = new ColorMatrix();
	// 改变亮度
       cMatrix.set(new float[] { 1, 0, 0, 0, brightness, 0, 1,    
               0, 0, brightness,
               0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 });    
       Paint paint = new Paint();    
       paint.setColorFilter(new ColorMatrixColorFilter(cMatrix));    
       Canvas canvas = new Canvas(bmp);    
       // 在Canvas上绘制一个Bitmap  
       canvas.drawBitmap(srcBitmap, 0, 0, paint);    
      return new BitmapDrawable(bmp);  
   }
 
Example #30
Source File: ColorFilterGenerator.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
private static void adjustContrast(ColorMatrix cm, float value) {
	value = cleanValue(value, 100);
	if (value == 0) {
		return;
	}
	float x;
	if (value < 0) {
		x = 127 + value / 100 * 127;
	} else {
		x = value % 1;
		if (x == 0) {
			x = (float) DELTA_INDEX[(int)Math.floor(value)];
		} else {
			x = (float) DELTA_INDEX[(int) Math.floor(value)] * (1 - x)
					+ (float) DELTA_INDEX[(int) Math.floor(value) + 1] * x; 
		}
		x = x * 127 + 127;
	}

	float[] mat = new float[] { x / 127, 0, 0, 0, 0.5f * (127 - x), 0,
			x / 127, 0, 0, 0.5f * (127 - x), 0, 0, x / 127, 0,
			0.5f * (127 - x), 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 };
	cm.postConcat(new ColorMatrix(mat));

}