Search in sources :

Example 6 with ColorMatrix

use of android.graphics.ColorMatrix in project robolectric by robolectric.

the class ShadowBitmapTest method shouldReceiveDescriptionWhenDrawABitmapToCanvasWithAPaintEffect.

@Test
public void shouldReceiveDescriptionWhenDrawABitmapToCanvasWithAPaintEffect() throws Exception {
    Bitmap bitmap1 = create("Bitmap One", 100, 100);
    Bitmap bitmap2 = create("Bitmap Two", 100, 100);
    Canvas canvas = new Canvas(bitmap1);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix()));
    canvas.drawBitmap(bitmap2, new Matrix(), paint);
    assertThat(shadowOf(bitmap1).getDescription()).isEqualTo("Bitmap One\n" + "Bitmap Two with ColorMatrixColorFilter<1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0>" + " transformed by Matrix[pre=[], set={}, post=[]]");
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) ColorMatrix(android.graphics.ColorMatrix) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint) Test(org.junit.Test)

Example 7 with ColorMatrix

use of android.graphics.ColorMatrix in project Lazy by l123456789jy.

the class BitmapUtil method lumAndHueAndSaturation.

/**
     * 亮度、色相、饱和度处理
     *
     * @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;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint)

Example 8 with ColorMatrix

use of android.graphics.ColorMatrix in project Lazy by l123456789jy.

the class BitmapUtil method saturation.

/**
     * 饱和度处理
     *
     * @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;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint)

Example 9 with ColorMatrix

use of android.graphics.ColorMatrix in project Lazy by l123456789jy.

the class ImageProcessor method lumAndHueAndSaturation.

/**
     * 亮度、色相、饱和度处理
     * @param lumValue 亮度值
     * @param hueValue 色相值
     * @param saturationValue 饱和度值
     * @return 亮度、色相、饱和度处理后的图片
     */
public Bitmap lumAndHueAndSaturation(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(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    //将原图使用给定的画笔画到画布上
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint)

Example 10 with ColorMatrix

use of android.graphics.ColorMatrix in project Lazy by l123456789jy.

the class ImageProcessor method saturation.

/**
     * 饱和度处理
     * @param saturationValue 新的饱和度值
     * @return 改变了饱和度值之后的图片
     */
public Bitmap saturation(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(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    //将原图使用给定的画笔画到画布上
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint)

Aggregations

ColorMatrix (android.graphics.ColorMatrix)46 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)46 Paint (android.graphics.Paint)29 Canvas (android.graphics.Canvas)28 Bitmap (android.graphics.Bitmap)27 Resources (android.content.res.Resources)4 BlurMaskFilter (android.graphics.BlurMaskFilter)4 Rect (android.graphics.Rect)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 DisplayMetrics (android.util.DisplayMetrics)4 ImageView (android.widget.ImageView)4 Drawable (android.graphics.drawable.Drawable)3 Matrix (android.graphics.Matrix)2 Path (android.graphics.Path)2 View (android.view.View)2 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)2 ShadowView (carbon.shadow.ShadowView)2 ShortcutPickHelper (com.android.settingslib.cm.ShortcutPickHelper)2 ValueAnimator (com.nineoldandroids.animation.ValueAnimator)2 Test (org.junit.Test)2