Java Code Examples for android.graphics.ColorMatrix#setScale()

The following examples show how to use android.graphics.ColorMatrix#setScale() . 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: 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 2
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 3
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 4
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 5
Source File: BitmapUtil.java    From AndroidStudyDemo with GNU General Public License v2.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 6
Source File: ImageFilterUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 亮度处理
 * @param bitmap   待操作源图片
 * @param lumValue 新的亮度值
 * @return 改变了亮度值之后的图片
 */
public static Bitmap lum(final Bitmap bitmap, final int lumValue) {
    if (bitmap == null) return null;
    try {
        // 计算出符合要求的亮度值
        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(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(newBitmap);
        // 将源图片使用给定的画笔画到画布上
        canvas.drawBitmap(bitmap, 0, 0, paint);
        return newBitmap;
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "lum");
    }
    return null;
}
 
Example 7
Source File: BitmapUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 亮度、色相、饱和度处理
 *
 * @param bitmap          原图
 * @param lumValue        亮度值
 * @param hueValue        色相值
 * @param saturationValue 饱和度值
 * @return 亮度、色相、饱和度处理后的图片
 */
public static Bitmap lumAndHueAndSaturation(Bitmap bitmap, int lumValue,
                                            int hueValue, int saturationValue) {
    // 计算出符合要求的饱和度值
    float newSaturationValue = saturationValue * 1.0F / 127;
    // 计算出符合要求的亮度值
    float newlumValue = lumValue * 1.0F / 127;
    // 计算出符合要求的色相值
    float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;

    // 创建一个颜色矩阵并设置其饱和度
    ColorMatrix colorMatrix = new ColorMatrix();

    // 设置饱和度值
    colorMatrix.setSaturation(newSaturationValue);
    // 设置亮度值
    colorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
    // 控制让红色区在色轮上旋转的角度
    colorMatrix.setRotate(0, newHueValue);
    // 控制让绿红色区在色轮上旋转的角度
    colorMatrix.setRotate(1, newHueValue);
    // 控制让蓝色区在色轮上旋转的角度
    colorMatrix.setRotate(2, newHueValue);

    // 创建一个画笔并设置其颜色过滤器
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    // 创建一个新的图片并创建画布
    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 8
Source File: FoldingLayoutActivity.java    From Folding-Android with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	setContentView(R.layout.activity_fold);

	mImageView = (ImageView) findViewById(R.id.image_view);
	mImageView.setPadding(ANTIALIAS_PADDING, ANTIALIAS_PADDING,
			ANTIALIAS_PADDING, ANTIALIAS_PADDING);
	mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
	mImageView.setImageDrawable(getResources()
			.getDrawable(R.drawable.image));

	if (IS_ISC) {
		//mTextureView = new TextureView(this);
		//mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
	}

	mAnchorSeekBar = (SeekBar) findViewById(R.id.anchor_seek_bar);
	mFoldLayout = (FoldingLayout) findViewById(R.id.fold_view);

	mFoldLayout.setFoldListener(mOnFoldListener);

	mAnchorSeekBar.setOnSeekBarChangeListener(mSeekBarChangeListener);

	mItemSelectedListener = new ItemSelectedListener();

	mDefaultPaint = new Paint();
	mSepiaPaint = new Paint();

	ColorMatrix m1 = new ColorMatrix();
	ColorMatrix m2 = new ColorMatrix();
	m1.setSaturation(0);
	m2.setScale(1f, .95f, .82f, 1.0f);
	m1.setConcat(m2, m1);
	mSepiaPaint.setColorFilter(new ColorMatrixColorFilter(m1));
}
 
Example 9
Source File: FoldingLayoutActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.folding_drawer_activity_fold);

    mImageView = (ImageView) findViewById(R.id.image_view);
    mImageView.setPadding(ANTIALIAS_PADDING, ANTIALIAS_PADDING,
            ANTIALIAS_PADDING, ANTIALIAS_PADDING);
    mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
    mImageView.setImageDrawable(getResources()
            .getDrawable(R.drawable.test));

    if (IS_ISC) {
        //mTextureView = new TextureView(this);
        //mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
    }

    mAnchorSeekBar = (SeekBar) findViewById(R.id.anchor_seek_bar);
    mFoldLayout = (FoldingLayout) findViewById(R.id.fold_view);

    mFoldLayout.setFoldListener(mOnFoldListener);

    mAnchorSeekBar.setOnSeekBarChangeListener(mSeekBarChangeListener);

    mItemSelectedListener = new ItemSelectedListener();

    mDefaultPaint = new Paint();
    mSepiaPaint = new Paint();

    ColorMatrix m1 = new ColorMatrix();
    ColorMatrix m2 = new ColorMatrix();
    m1.setSaturation(0);
    m2.setScale(1f, .95f, .82f, 1.0f);
    m1.setConcat(m2, m1);
    mSepiaPaint.setColorFilter(new ColorMatrixColorFilter(m1));
    mFoldLayout.setNumberOfFolds(mNumberOfFolds);
}
 
Example 10
Source File: ColorMatrixActivity.java    From android-graphics-demo with Apache License 2.0 5 votes vote down vote up
private ColorMatrix getSepiaColorMatrix() {
  ColorMatrix colorMatrix = new ColorMatrix();
  colorMatrix.setSaturation(0);

  ColorMatrix colorScale = new ColorMatrix();
  colorScale.setScale(1, 1, 0.8f, 1);

  // Convert to grayscale, then apply brown color
  colorMatrix.postConcat(colorScale);

  return colorMatrix;
}
 
Example 11
Source File: FastBitmapDrawable.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
private static void setBrightnessMatrix(ColorMatrix matrix, int brightness) {
    // Brightness: C-new = C-old*(1-amount) + amount
    float scale = 1 - brightness / 255.0f;
    matrix.setScale(scale, scale, scale, 1);
    float[] array = matrix.getArray();

    // Add the amount to RGB components of the matrix, as per the above formula.
    // Fifth elements in the array correspond to the constant being added to
    // red, blue, green, and alpha channel respectively.
    array[4] = brightness;
    array[9] = brightness;
    array[14] = brightness;
}
 
Example 12
Source File: CircleLoadingView.java    From CircleLoadingView with MIT License 5 votes vote down vote up
public CircleLoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    ColorMatrix cm = new ColorMatrix();
    cm.setScale(0.382f, 0.382f, 0.382f, 1f);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    mGrayPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mGrayPaint.setColorFilter(f);
    mArcPaint = new Paint((Paint.ANTI_ALIAS_FLAG));
    mRingPaint = new Paint((Paint.ANTI_ALIAS_FLAG));
    mCirclePaint = new Paint((Paint.ANTI_ALIAS_FLAG));
    mNormalPaint = new Paint((Paint.ANTI_ALIAS_FLAG));
    mAnimationState = 2;
    final TypedArray typedArray = context
            .obtainStyledAttributes(attrs, R.styleable.CircleLoadingView);
    try {
        Drawable drawable = typedArray
                .getDrawable(R.styleable.CircleLoadingView_cl_src);
        mCircleRadius = typedArray
                .getDimensionPixelSize(R.styleable.CircleLoadingView_cl_circleRadius, -1);
        mAnimationDuration = typedArray
                .getFloat(R.styleable.CircleLoadingView_cl_fillAnimationDuration, 800);
        mCircleStrokeSize = typedArray
                .getDimensionPixelSize(R.styleable.CircleLoadingView_cl_circleStrokeSize, -1);
        if (drawable instanceof BitmapDrawable) {
            mOriginBitmap = ((BitmapDrawable) drawable).getBitmap();
            initRect();
        }
    } finally {
        typedArray.recycle();
    }
}
 
Example 13
Source File: FastBitmapDrawable.java    From FastAccess with GNU General Public License v3.0 5 votes vote down vote up
private static void setBrightnessMatrix(ColorMatrix matrix, int brightness) {
    // Brightness: C-new = C-old*(1-amount) + amount
    float scale = 1 - brightness / 255.0f;
    matrix.setScale(scale, scale, scale, 1);
    float[] array = matrix.getArray();

    // Add the amount to RGB components of the matrix, as per the above formula.
    // Fifth elements in the array correspond to the constant being added to
    // red, blue, green, and alpha channel respectively.
    array[4] = brightness;
    array[9] = brightness;
    array[14] = brightness;
}
 
Example 14
Source File: FastBitmapDrawable.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
private static void setBrightnessMatrix(ColorMatrix matrix, int brightness) {
    // Brightness: C-new = C-old*(1-amount) + amount
    float scale = 1 - brightness / 255.0f;
    matrix.setScale(scale, scale, scale, 1);
    float[] array = matrix.getArray();

    // Add the amount to RGB components of the matrix, as per the above formula.
    // Fifth elements in the array correspond to the constant being added to
    // red, blue, green, and alpha channel respectively.
    array[4] = brightness;
    array[9] = brightness;
    array[14] = brightness;
}
 
Example 15
Source File: XBitmapUtils.java    From XFrame with Apache License 2.0 5 votes vote down vote up
/**
 * 亮度、色相、饱和度处理
 *
 * @param bitmap          原图
 * @param lumValue        亮度值
 * @param hueValue        色相值
 * @param saturationValue 饱和度值
 * @return 亮度、色相、饱和度处理后的图片
 */
public static Bitmap lumAndHueAndSaturation(Bitmap bitmap, int lumValue,
                                            int hueValue, int saturationValue) {
    // 计算出符合要求的饱和度值
    float newSaturationValue = saturationValue * 1.0F / 127;
    // 计算出符合要求的亮度值
    float newlumValue = lumValue * 1.0F / 127;
    // 计算出符合要求的色相值
    float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;

    // 创建一个颜色矩阵并设置其饱和度
    ColorMatrix colorMatrix = new ColorMatrix();

    // 设置饱和度值
    colorMatrix.setSaturation(newSaturationValue);
    // 设置亮度值
    colorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
    // 控制让红色区在色轮上旋转的角度
    colorMatrix.setRotate(0, newHueValue);
    // 控制让绿红色区在色轮上旋转的角度
    colorMatrix.setRotate(1, newHueValue);
    // 控制让蓝色区在色轮上旋转的角度
    colorMatrix.setRotate(2, newHueValue);

    // 创建一个画笔并设置其颜色过滤器
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    // 创建一个新的图片并创建画布
    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 16
Source File: ImageUtils.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 5 votes vote down vote up
/**
 * Returns a sepia filtered version of src.
 *
 * @param src source image.
 * @return sepia filtered image.
 */
static Bitmap sepiaBitmap(Bitmap src) {

    ColorMatrix colorMatrix_Sepia = new ColorMatrix();
    colorMatrix_Sepia.setSaturation(0);

    ColorMatrix colorScale = new ColorMatrix();
    colorScale.setScale(1, 1, 0.8f, 1);
    colorMatrix_Sepia.postConcat(colorScale);

    ColorFilter ColorFilter_Sepia = new ColorMatrixColorFilter(colorMatrix_Sepia);
    Bitmap      bitmap            = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas      canvas            = new Canvas(bitmap);
    Paint       paint             = new Paint();

    paint.setColorFilter(ColorFilter_Sepia);
    canvas.drawBitmap(src, 0, 0, paint);

    return bitmap;
}
 
Example 17
Source File: ImageFilterUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 亮度、色相、饱和度处理
 * @param bitmap          待操作源图片
 * @param lumValue        亮度值
 * @param hueValue        色相值
 * @param saturationValue 饱和度值
 * @return 亮度、色相、饱和度处理后的图片
 */
public static Bitmap lumHueSaturation(final Bitmap bitmap, final int lumValue, final int hueValue, final int saturationValue) {
    if (bitmap == null) return null;
    try {
        // 计算出符合要求的饱和度值
        float newSaturationValue = saturationValue * 1.0F / 127;
        // 计算出符合要求的亮度值
        float newlumValue = lumValue * 1.0F / 127;
        // 计算出符合要求的色相值
        float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;
        // 创建一个颜色矩阵并设置其饱和度
        ColorMatrix colorMatrix = new ColorMatrix();
        // 设置饱和度值
        colorMatrix.setSaturation(newSaturationValue);
        // 设置亮度值
        colorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
        // 控制让红色区在色轮上旋转的角度
        colorMatrix.setRotate(0, newHueValue);
        // 控制让绿红色区在色轮上旋转的角度
        colorMatrix.setRotate(1, newHueValue);
        // 控制让蓝色区在色轮上旋转的角度
        colorMatrix.setRotate(2, newHueValue);
        // 创建一个画笔并设置其颜色过滤器
        Paint paint = new Paint();
        paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
        // 创建一个新的图片并创建画布
        Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(newBitmap);
        // 将源图片使用给定的画笔画到画布上
        canvas.drawBitmap(bitmap, 0, 0, paint);
        return newBitmap;
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "lumHueSaturation");
    }
    return null;
}
 
Example 18
Source File: DragView.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
public static void setColorScale(int color, ColorMatrix target) {
    target.setScale(Color.red(color) / 255f, Color.green(color) / 255f,
            Color.blue(color) / 255f, Color.alpha(color) / 255f);
}
 
Example 19
Source File: MainActivity.java    From auid2 with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        final View view = findViewById(R.id.view);
        final ImageView imageView = (ImageView) findViewById(R.id.image);

        // SimpleTextDrawable
//        view.setBackgroundDrawable(new SimpleTextDrawable("Hello World!"));

        // BetterTextDrawable
//        view.setBackgroundDrawable(new BetterTextDrawable("This is a really long string of text that will require multiple lines."));

        // SimpleImageDrawable
        final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
        final SimpleImageDrawable simpleImageDrawable = new SimpleImageDrawable(bitmap);
//        view.setBackgroundDrawable(simpleImageDrawable);


        // LightingColorFilter example
        //                AARRGGBB
        final int mul = 0xFF00FF00;
        final int add = 0x000000BB;
        final ColorFilter lightingColorFilter = new LightingColorFilter(mul, add);
//        simpleImageDrawable.setColorFilter(lightingColorFilter);

        // ColorMatrixColorFilter example
        final ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(0);
        final ColorMatrix colorScale = new ColorMatrix();
        colorScale.setScale(2f, .68f, .26f, 1f); // Orange
        colorMatrix.postConcat(colorScale);
//        simpleImageDrawable.setColorFilter(new ColorMatrixColorFilter(colorMatrix));

        // RoundedImageDrawable
        final Bitmap largeBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.giwajip);
        final RoundedImageDrawable roundedImageDrawable = new RoundedImageDrawable(largeBitmap, 200);
//        imageView.setImageDrawable(roundedImageDrawable);

        // FadedImageDrawable
        final FadedImageDrawable fadedImageDrawable = new FadedImageDrawable(largeBitmap);
        imageView.setImageDrawable(fadedImageDrawable);
    }
 
Example 20
Source File: ThemeUtils.java    From LaunchEnr with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Scales a color matrix such that, when applied to color R G B A, it produces R' G' B' A' where
 * R' = r * R
 * G' = g * G
 * B' = b * B
 * A' = a * A
 * <p>
 * The matrix will, for instance, turn white into r g b a, and black will remain black.
 *
 * @param color  The color r g b a
 * @param target The ColorMatrix to scale
 */
public static void setColorScaleOnMatrix(int color, ColorMatrix target) {
    target.setScale(Color.red(color) / 255f, Color.green(color) / 255f,
            Color.blue(color) / 255f, Color.alpha(color) / 255f);
}