Search in sources :

Example 26 with ColorMatrix

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

the class ImageProcessor method hue.

/**
     * 色相处理
     * @param hueValue 新的色相值
     * @return 改变了色相值之后的图片
     */
public Bitmap hue(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(), 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 27 with ColorMatrix

use of android.graphics.ColorMatrix in project MyDiary by erttyy8821.

the class PageEffectView method init.

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 < 2012) {
        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());
    // 不让x,y为0,否则在点计算时会有问题
    mTouch.x = 0.01f;
    mTouch.y = 0.01f;
    //Set today text
    calendarFactory.onDraw(mCurrentPageCanvas);
}
Also used : Path(android.graphics.Path) ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorMatrix(android.graphics.ColorMatrix) Matrix(android.graphics.Matrix) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint) Scroller(android.widget.Scroller) Paint(android.graphics.Paint)

Example 28 with ColorMatrix

use of android.graphics.ColorMatrix in project boilerplate by koush.

the class TintHelper method setColorFilter.

static void setColorFilter(Drawable drawable, int color) {
    ColorMatrix s = new ColorMatrix();
    s.setScale(1 - Color.red(color) / 255f, 1 - Color.green(color) / 255f, 1 - Color.blue(color) / 255f, 1);
    s.preConcat(colorMatrixNegative);
    s.postConcat(colorMatrixNegative);
    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(s);
    drawable.setColorFilter(filter);
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorMatrix(android.graphics.ColorMatrix)

Example 29 with ColorMatrix

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

the class BitmapUtil method lum.

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

Example 30 with ColorMatrix

use of android.graphics.ColorMatrix in project Launcher3 by chislon.

the class WidgetPreviewLoader method generateShortcutPreview.

private Bitmap generateShortcutPreview(ResolveInfo info, int maxWidth, int maxHeight, Bitmap preview) {
    Bitmap tempBitmap = mCachedShortcutPreviewBitmap.get();
    final Canvas c = mCachedShortcutPreviewCanvas.get();
    if (tempBitmap == null || tempBitmap.getWidth() != maxWidth || tempBitmap.getHeight() != maxHeight) {
        tempBitmap = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
        mCachedShortcutPreviewBitmap.set(tempBitmap);
    } else {
        c.setBitmap(tempBitmap);
        c.drawColor(0, PorterDuff.Mode.CLEAR);
        c.setBitmap(null);
    }
    // Render the icon
    Drawable icon = mIconCache.getFullResIcon(info);
    int paddingTop = mContext.getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top);
    int paddingLeft = mContext.getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left);
    int paddingRight = mContext.getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
    int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
    renderDrawableToBitmap(icon, tempBitmap, paddingLeft, paddingTop, scaledIconWidth, scaledIconWidth);
    if (preview != null && (preview.getWidth() != maxWidth || preview.getHeight() != maxHeight)) {
        throw new RuntimeException("Improperly sized bitmap passed as argument");
    } else if (preview == null) {
        preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
    }
    c.setBitmap(preview);
    // Draw a desaturated/scaled version of the icon in the background as a watermark
    Paint p = mCachedShortcutPreviewPaint.get();
    if (p == null) {
        p = new Paint();
        ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(0);
        p.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
        p.setAlpha((int) (255 * 0.06f));
        mCachedShortcutPreviewPaint.set(p);
    }
    c.drawBitmap(tempBitmap, 0, 0, p);
    c.setBitmap(null);
    renderDrawableToBitmap(icon, preview, 0, 0, mAppIconSize, mAppIconSize);
    return preview;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint) 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