Search in sources :

Example 26 with Paint

use of android.graphics.Paint in project BGABadgeView-Android by bingoogolapple.

the class BGABadgeViewHelper method initDefaultAttrs.

private void initDefaultAttrs(Context context, BadgeGravity defaultBadgeGravity) {
    mBadgeNumberRect = new Rect();
    mBadgeRectF = new RectF();
    mBadgeBgColor = Color.RED;
    mBadgeTextColor = Color.WHITE;
    mBadgeTextSize = BGABadgeViewUtil.sp2px(context, 10);
    mBadgePaint = new Paint();
    mBadgePaint.setAntiAlias(true);
    mBadgePaint.setStyle(Paint.Style.FILL);
    // 设置mBadgeText居中,保证mBadgeText长度为1时,文本也能居中
    mBadgePaint.setTextAlign(Paint.Align.CENTER);
    mBadgePadding = BGABadgeViewUtil.dp2px(context, 4);
    mBadgeVerticalMargin = BGABadgeViewUtil.dp2px(context, 4);
    mBadgeHorizontalMargin = BGABadgeViewUtil.dp2px(context, 4);
    mBadgeGravity = defaultBadgeGravity;
    mIsShowBadge = false;
    mBadgeText = null;
    mBitmap = null;
    mIsDraging = false;
    mDragable = false;
    mBadgeBorderColor = Color.WHITE;
    mDragExtra = BGABadgeViewUtil.dp2px(context, 4);
    mBadgeDragExtraRectF = new RectF();
}
Also used : RectF(android.graphics.RectF) Rect(android.graphics.Rect) Paint(android.graphics.Paint)

Example 27 with Paint

use of android.graphics.Paint 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 28 with Paint

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

the class BitmapUtil method combineImagesToSameSize.

/**
     * 合并
     * @param bgd 后景Bitmap
     * @param fg 前景Bitmap
     * @return 合成后Bitmap
     */
public static Bitmap combineImagesToSameSize(Bitmap bgd, Bitmap fg) {
    Bitmap bmp;
    int width = bgd.getWidth() < fg.getWidth() ? bgd.getWidth() : fg.getWidth();
    int height = bgd.getHeight() < fg.getHeight() ? bgd.getHeight() : fg.getHeight();
    if (fg.getWidth() != width && fg.getHeight() != height) {
        fg = zoom(fg, width, height);
    }
    if (bgd.getWidth() != width && bgd.getHeight() != height) {
        bgd = zoom(bgd, width, height);
    }
    bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_ATOP));
    Canvas canvas = new Canvas(bmp);
    canvas.drawBitmap(bgd, 0, 0, null);
    canvas.drawBitmap(fg, 0, 0, paint);
    return bmp;
}
Also used : Bitmap(android.graphics.Bitmap) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 29 with Paint

use of android.graphics.Paint in project TwinklingRefreshLayout by lcodecorex.

the class GoogleDotView method init.

private void init() {
    r = DensityUtil.dp2px(getContext(), 4);
    mPath = new Paint();
    mPath.setAntiAlias(true);
    mPath.setColor(Color.rgb(114, 114, 114));
    animator1 = ValueAnimator.ofFloat(1f, 1.2f, 1f, 0.8f);
    animator1.setDuration(800);
    animator1.setInterpolator(new DecelerateInterpolator());
    animator1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            fraction1 = (float) animation.getAnimatedValue();
            invalidate();
        }
    });
    animator1.setRepeatCount(ValueAnimator.INFINITE);
    animator1.setRepeatMode(ValueAnimator.REVERSE);
    animator2 = ValueAnimator.ofFloat(1f, 0.8f, 1f, 1.2f);
    animator2.setDuration(800);
    animator2.setInterpolator(new DecelerateInterpolator());
    animator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            fraction2 = (float) animation.getAnimatedValue();
        }
    });
    animator2.setRepeatCount(ValueAnimator.INFINITE);
    animator2.setRepeatMode(ValueAnimator.REVERSE);
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Paint(android.graphics.Paint) ValueAnimator(android.animation.ValueAnimator)

Example 30 with Paint

use of android.graphics.Paint in project TwinklingRefreshLayout by lcodecorex.

the class RoundProgressView method init.

private void init() {
    mPath = new Paint();
    mPantR = new Paint();
    mPantR.setColor(Color.WHITE);
    mPantR.setAntiAlias(true);
    mPath.setAntiAlias(true);
    mPath.setColor(Color.rgb(114, 114, 114));
    va = ValueAnimator.ofInt(0, 360);
    va.setDuration(720);
    va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            endAngle = (int) animation.getAnimatedValue();
            postInvalidate();
        }
    });
    va.setRepeatCount(ValueAnimator.INFINITE);
    va.setInterpolator(new AccelerateDecelerateInterpolator());
}
Also used : AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) Paint(android.graphics.Paint) ValueAnimator(android.animation.ValueAnimator)

Aggregations

Paint (android.graphics.Paint)2242 Canvas (android.graphics.Canvas)465 Bitmap (android.graphics.Bitmap)415 Rect (android.graphics.Rect)267 RectF (android.graphics.RectF)231 TextPaint (android.text.TextPaint)178 PorterDuffXfermode (android.graphics.PorterDuffXfermode)124 Path (android.graphics.Path)120 Matrix (android.graphics.Matrix)105 TypedArray (android.content.res.TypedArray)81 BitmapDrawable (android.graphics.drawable.BitmapDrawable)75 Drawable (android.graphics.drawable.Drawable)64 BitmapShader (android.graphics.BitmapShader)63 Point (android.graphics.Point)60 SuppressLint (android.annotation.SuppressLint)55 View (android.view.View)54 Resources (android.content.res.Resources)42 Test (org.junit.Test)40 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)39 Typeface (android.graphics.Typeface)39