Java 类android.graphics.PorterDuffXfermode 实例源码

项目:mine-android-repository    文件:BitmapUtils.java   
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(outBitmap);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPX = bitmap.getWidth() / 2;
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPX, roundPX, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return outBitmap;
}
项目:mine-android-repository    文件:BitmapUtils.java   
/**
 * 图片圆角处理
 *
 * @param bitmap
 * @param roundPX
 * @return
 */
public static Bitmap getRCB(Bitmap bitmap, float roundPX) {
    // RCB means
    // Rounded
    // Corner Bitmap
    Bitmap dstbmp = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(dstbmp);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPX, roundPX, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return dstbmp;
}
项目:utilsLibrary    文件:BitmapUtils.java   
/**
 * 图片圆角处理
 *
 * @param bitmap
 * @param roundPX
 * @return
 */
public static Bitmap getRoundBitmap(Bitmap bitmap, float roundPX) {
    // RCB means
    // Rounded
    // Corner Bitmap
    Bitmap dstbmp = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(dstbmp);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPX, roundPX, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return dstbmp;
}
项目:open-rmbt    文件:Gauge.java   
public Gauge(final float startAngle, final float maxAngle, final Bitmap background, final Bitmap dynamic,
        final Bitmap foreground, final float x1, final float y1, final float x2, final float y2)
{
    this.startAngle = startAngle;
    this.maxAngle = maxAngle;
    this.background = background;
    this.dynamic = dynamic;
    this.foreground = foreground;
    width = background.getWidth();
    height = background.getHeight();
    drawBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    drawCanvas = new Canvas(drawBitmap);

    paint.setFilterBitmap(true);

    Log.d(LOG, "density background: " + background.getDensity());

    erasePaint = new Paint();
    erasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
    erasePaint.setAntiAlias(true);
    // erasePaint.setAlpha(0);

    ovalRect = new RectF(width * x1, height * y1, width * x2, height * y2);
}
项目:AndroidDumbStructure    文件:ImageShaper.java   
public static Bitmap getRoundedCornerImage(Bitmap bitmap,int radius) {
    Bitmap finalBitmap;
    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
        finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius,
                false);
    else
        finalBitmap = bitmap;
    Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
            finalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
            finalBitmap.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(finalBitmap.getWidth() / 2 + 0.7f,finalBitmap.getHeight() / 2 + 0.7f,finalBitmap.getWidth() / 2 +                                      0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
}
项目:GitHub    文件:BitmapUtils.java   
public static Bitmap circleBitmap(Bitmap source) {
    //获取图片的宽度
    int width = source.getWidth();
    //创建一个与source等宽的Bitmap对象
    Bitmap bitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);
    //创建等大小的画布
    Canvas canvas = new Canvas(bitmap);
    //绘制一个圆圈:将此圆圈理解为下层图片
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    canvas.drawCircle(width / 2, width / 2, width / 2, paint);

    //设置图片相交情况下的处理方式
    //setXfermode:设置当绘制的图像出现相交情况时候的处理方式的,它包含的常用模式有哪几种
    //PorterDuff.Mode.SRC_IN 取两层图像交集部门,只显示上层图像,注意这里是指取相交叉的部分,然后显示上层图像
    //PorterDuff.Mode.DST_IN 取两层图像交集部门,只显示下层图像
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    //source:理解为上层图片
    canvas.drawBitmap(source, 0, 0, paint);

    return bitmap;
}
项目:GitHub    文件:ImageDecoder.java   
/**
 * 裁剪圆形图片
 *
 * @param source
 * @param recycleSource 裁剪成功后销毁原图
 * @return
 */
public static Bitmap cut2Circular(Bitmap source, boolean recycleSource) {
    int width = source.getWidth();
    int height = source.getHeight();
    int diameter = Math.min(width, height);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    Bitmap result = Bitmap.createBitmap(diameter, diameter, Bitmap.Config.ARGB_8888);
    if (result != null) {
        Canvas canvas = new Canvas(result);
        canvas.drawCircle(diameter / 2, diameter / 2, diameter / 2, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(source, (diameter - width) / 2, (diameter - height) / 2, paint);
        if (recycleSource) {
            source.recycle();
            source = null;
        }
    } else {
        result = source;
    }
    return result;
}
项目:TakePhoto    文件:FileUtil.java   
/**
 * 将图片变为圆角
 * @param bitmap 原Bitmap图片
 * @param pixels 图片圆角的弧度(单位:像素(px))
 * @return 带有圆角的图片(Bitmap 类型)
 */
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}
项目:MusicX-music-player    文件:RoundRectImageView.java   
private void init() {
    //without hardware level gpu more
    setLayerType(View.LAYER_TYPE_HARDWARE, null);
    mColor = Color.argb(100, 200, 50, 50);
    mCirclePaint = new Paint();
    mCirclePaint.setStyle(Paint.Style.FILL);
    mCirclePaint.setColor(mColor);
    mCirclePaint.setAntiAlias(true);

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(Color.BLACK);

    mMaskPaint = new Paint();
    mMaskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
}
项目:Blogg    文件:Tools.java   
public static Bitmap getCroppedBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
            bitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    //Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false);
    //return _bmp;
    return output;
}
项目:RLibrary    文件:ImageUtils.java   
/**
 * 转为圆形图片
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return 圆形图片
 */
public static Bitmap toRound(Bitmap src, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    int radius = Math.min(width, height) >> 1;
    Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
    Paint paint = new Paint();
    Canvas canvas = new Canvas(ret);
    Rect rect = new Rect(0, 0, width, height);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(width >> 1, height >> 1, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(src, rect, rect, paint);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
项目:AppCommonFrame    文件:BitmapUtil.java   
/**
 * 两张图片合成一张图片圆角的图片 . <br>
 * @author liulongzhenhai 2013-10-28 上午11:24:15 <br>
 * @param outBitmap1 背景图片
 * @param bitmap 要生成圆角的图片
 * @return Bitmap Bitmap
 */
public static Bitmap getRoundedCornerBitmap(final Bitmap outBitmap1, final Bitmap bitmap) {
    final int sm = 0;
    // Log.w("outHeight",outBitmap.getHeight()+","+outBitmap.getWidth());
    final Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    final Canvas canvas = new Canvas(outBitmap);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(sm, sm, bitmap.getWidth() - sm, bitmap.getHeight() - sm);
    final RectF rectF = new RectF(rect);
    final float roundPX = bitmap.getWidth() / 2;
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPX, roundPX, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return outBitmap;
}
项目:rongyunDemo    文件:BitmapUtils.java   
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
                                        bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 12;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    if (null != bitmap) {
        bitmap.recycle();
        bitmap = null;
    }

    return output;
}
项目:EasyTodo    文件:CheckBoxSample.java   
private void init(Context context, AttributeSet attrs) {
    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.CheckBox_Sample);
    size = ta.getDimensionPixelSize(R.styleable.CheckBox_Sample_size, dp(size));
    bitmapColor = ta.getColor(R.styleable.CheckBox_Sample_color_background, bitmapColor);
    borderColor = ta.getColor(R.styleable.CheckBox_Sample_color_border, borderColor);

    bitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    bitmapEraser = new Paint(Paint.ANTI_ALIAS_FLAG);
    bitmapEraser.setColor(0);
    bitmapEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    checkEraser = new Paint(Paint.ANTI_ALIAS_FLAG);
    checkEraser.setColor(0);
    checkEraser.setStyle(Paint.Style.STROKE);
    checkEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    borderPaint.setStyle(Paint.Style.STROKE);
    borderPaint.setStrokeWidth(dp(2));
    checkDrawable = context.getResources().getDrawable(R.mipmap.check);
    setVisibility(VISIBLE);
    ta.recycle();
}
项目:chromium-for-android-56-debug-video    文件:ProfileDataCache.java   
private Bitmap getCroppedBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(
            bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.WHITE);

    final float radius =  (bitmap.getWidth() - mImageStrokePx) / 2f;
    canvas.drawCircle(bitmap.getWidth() / 2f, bitmap.getHeight() / 2f, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    paint.setColor(mImageStrokeColor);
    paint.setStyle(Paint.Style.STROKE);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC));
    paint.setStrokeWidth(mImageStrokePx);
    canvas.drawCircle(bitmap.getWidth() / 2f, bitmap.getHeight() / 2f, radius, paint);

    return output;
}
项目:adyen-android    文件:IconUtil.java   
private static Bitmap roundCorners(Bitmap bitmap, int radiusPx) {

        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(rect);
        final float roundPx = radiusPx;

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);

        return output;
    }
项目:Cable-Android    文件:ShapeScrim.java   
public ShapeScrim(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);

  if (attrs != null) {
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ShapeScrim, 0, 0);
    String     shapeName  = typedArray.getString(R.styleable.ShapeScrim_shape);

    if      ("square".equalsIgnoreCase(shapeName)) this.shape = ShapeType.SQUARE;
    else if ("circle".equalsIgnoreCase(shapeName)) this.shape = ShapeType.CIRCLE;
    else                                           this.shape = ShapeType.SQUARE;

    this.radius = typedArray.getFloat(R.styleable.ShapeScrim_radius, 0.4f);

    typedArray.recycle();
  } else {
    this.shape  = ShapeType.SQUARE;
    this.radius = 0.4f;
  }

  this.eraser = new Paint();
  this.eraser.setColor(0xFFFFFFFF);
  this.eraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
项目:Buttons    文件:Button.java   
@Nullable
private Bitmap getRipple() {
    if (getBackground() == null || getWidth() < 1 || getHeight() < 1)
        return null;

    Bitmap bitmap;
    try {
        bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
    } catch (OutOfMemoryError e) {
        return null;
    }

    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(this.paint.getColor());
    paint.setAlpha(255);

    getBackground().draw(canvas);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
    canvas.drawCircle(rippleX, rippleY, progress * (getWidth() / 1.5f), paint);

    return bitmap;
}
项目:PercentClipView    文件:PercentClipHelper.java   
private Bitmap createMask(int width, int height) {
    Bitmap mask = Bitmap.createBitmap(width, height, Bitmap.Config.ALPHA_8);
    Canvas canvas = new Canvas(mask);

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setAntiAlias(true);
    paint.setColor(Color.WHITE);
    canvas.drawRect(0, 0, width, height, paint);

    if (this.params.left + this.params.right >= 1) return mask;
    if (this.params.top + this.params.bottom >= 1) return mask;

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    canvas.drawRect(
            width * this.params.left, height * this.params.top,
            width * (1f - this.params.right), height * (1f - this.params.bottom),
            paint);
    return mask;
}
项目:MDWechat    文件:ImageHelper.java   
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
            .getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}
项目:PeSanKita-android    文件:ShapeScrim.java   
public ShapeScrim(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);

  if (attrs != null) {
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ShapeScrim, 0, 0);
    String     shapeName  = typedArray.getString(R.styleable.ShapeScrim_shape);

    if      ("square".equalsIgnoreCase(shapeName)) this.shape = ShapeType.SQUARE;
    else if ("circle".equalsIgnoreCase(shapeName)) this.shape = ShapeType.CIRCLE;
    else                                           this.shape = ShapeType.SQUARE;

    this.radius = typedArray.getFloat(R.styleable.ShapeScrim_radius, 0.4f);

    typedArray.recycle();
  } else {
    this.shape  = ShapeType.SQUARE;
    this.radius = 0.4f;
  }

  this.eraser = new Paint();
  this.eraser.setColor(0xFFFFFFFF);
  this.eraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
项目:MontageCam    文件:CustomPaintView.java   
private void init(Context context) {
    mPaint = new Paint();
    mPaint.setAntiAlias(true);

    mPaint.setColor(Color.RED);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);


    mEraserPaint = new Paint();
    mEraserPaint.setAlpha(0);
    mEraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    mEraserPaint.setAntiAlias(true);
    mEraserPaint.setDither(true);
    mEraserPaint.setStyle(Paint.Style.STROKE);
    mEraserPaint.setStrokeJoin(Paint.Join.ROUND);
    mEraserPaint.setStrokeCap(Paint.Cap.ROUND);
    mEraserPaint.setStrokeWidth(40);
}
项目:BaseCore    文件:ImageUtils.java   
/**
 * 转为圆角图片
 *
 * @param src     源图片
 * @param radius  圆角的度数
 * @param recycle 是否回收
 * @return 圆角图片
 */
public static Bitmap toRoundCorner(Bitmap src, float radius, boolean recycle) {
    if (null == src) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
    Paint paint = new Paint();
    Canvas canvas = new Canvas(ret);
    Rect rect = new Rect(0, 0, width, height);
    paint.setAntiAlias(true);
    canvas.drawRoundRect(new RectF(rect), radius, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(src, rect, rect, paint);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
项目:SmartChart    文件:PieChartRenderer.java   
public PieChartRenderer(Context context, Chart chart, PieChartDataProvider dataProvider) {
    super(context, chart);
    this.dataProvider = dataProvider;
    touchAdditional = ChartUtils.dp2px(density, DEFAULT_TOUCH_ADDITIONAL_DP);

    slicePaint.setAntiAlias(true);
    slicePaint.setStyle(Paint.Style.FILL);

    centerCirclePaint.setAntiAlias(true);
    centerCirclePaint.setStyle(Paint.Style.FILL);
    centerCirclePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));

    centerCircleText1Paint.setAntiAlias(true);
    centerCircleText1Paint.setTextAlign(Align.CENTER);

    centerCircleText2Paint.setAntiAlias(true);
    centerCircleText2Paint.setTextAlign(Align.CENTER);

    separationLinesPaint.setAntiAlias(true);
    separationLinesPaint.setStyle(Paint.Style.STROKE);
    separationLinesPaint.setStrokeCap(Paint.Cap.ROUND);
    separationLinesPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    separationLinesPaint.setColor(Color.TRANSPARENT);
}
项目:CompositionAvatar    文件:CompositionAvatarView.java   
private void init(AttributeSet attrs, int defStyle) {
    final TypedArray a = getContext().obtainStyledAttributes(attrs,
            R.styleable.CompositionAvatarView, defStyle, 0);

    int index = a.getInt(R.styleable.CompositionAvatarView_fitType, -1);
    if (index >= 0) {
        setDrawableFitType(sFitTypeArray[index]);
    }

    float gap = a.getFloat(R.styleable.CompositionAvatarView_gap, DEFAULT_GAP);
    mGap = Math.max(0f, Math.min(gap, 1f));
    a.recycle();

    setLayerType(LAYER_TYPE_SOFTWARE, null);

    mPaint.setColor(Color.BLACK);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

    initForEditMode();
}
项目:android-ripple-pulse-animation    文件:RoundedImageView.java   
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
    Bitmap sbmp;
    if(bmp.getWidth() != radius || bmp.getHeight() != radius)
        sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
    else
        sbmp = bmp;
    Bitmap output = Bitmap.createBitmap(sbmp.getWidth(),
            sbmp.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xffa19774;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f,
            sbmp.getWidth() / 2+0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);

    return output;
}
项目:VRPhoto    文件:BitmapUtils.java   
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(outBitmap);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPX = bitmap.getWidth() / 2;
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPX, roundPX, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return outBitmap;
}
项目:NoticeDog    文件:ProfilePhoto.java   
public static Bitmap getRoundedRectBitmap(Bitmap bitmap) {
    Bitmap result = null;
    try {
        int preferredSize = Math.min(bitmap.getWidth(), bitmap.getHeight());
        result = Bitmap.createBitmap(preferredSize, preferredSize, Config.ARGB_8888);
        Canvas canvas = new Canvas(result);
        Paint paint = new Paint();
        Rect rect = new Rect(0, 0, 300, 300);
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(-12434878);
        canvas.drawCircle((float) (preferredSize / 2), (float) (preferredSize / 2), (float) (preferredSize / 2), paint);
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
        return result;
    } catch (NullPointerException e) {
        return result;
    } catch (OutOfMemoryError e2) {
        return result;
    }
}
项目:XERUNG    文件:LayoutRipple.java   
/**
 * @param bitmap
 * @return 设置涟漪的边界,涟漪在这个区域里面可见。这里可以设置四角的弧度数
 */
public Bitmap cropRoundRect(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
    bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    RectF rectF = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
    canvas.drawRoundRect(rectF, rippleBorderRadius, rippleBorderRadius, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
项目:TestChat    文件:CommonUtils.java   
/**
 * 获取圆形图片
 *
 * @param bitmap 源bitmap
 * @return 圆形bitmap
 */
public static Bitmap getCircleBitmap(Bitmap bitmap) {
        Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(outBitmap);
        float roundSize;
        roundSize = Math.min(bitmap.getHeight(), bitmap.getWidth()) / 2f;
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(Color.WHITE);
        RectF rectF = new RectF(0, 0, roundSize * 2, roundSize * 2);
        Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        canvas.drawRoundRect(rectF, roundSize, roundSize, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, new Rect(0, 0, Math.min(bitmap.getHeight(), bitmap.getWidth()), Math.min(bitmap.getHeight(), bitmap.getWidth())), paint);
        return outBitmap;
}
项目:NovelReader    文件:CircleTransform.java   
/**
 *
 * @param pool : 图片池,这个之后会谈到。
 * @param toTransform:需要进行处理的图片
 * @param outWidth:图片的宽
 * @param outHeight:图片的高
 * @return 返回处理完的图片
 */
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
    Paint paint = new Paint();
    //初始化画笔
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);
    paint.setDither(true);

    int width = toTransform.getWidth();
    int height = toTransform.getHeight();
    int size = Math.min(width,height);
    int x = (width - size)/2;
    int y = (height - size)/2;
    Bitmap result = pool.get(size,size, Bitmap.Config.ARGB_8888);
    if (result == null){
        result = Bitmap.createBitmap(size,size,Bitmap.Config.ARGB_8888);
    }
    //
    Canvas canvas = new Canvas(result);
    int radius = size/2;
    canvas.drawCircle(radius,radius,radius,paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(toTransform,-x,-y,paint);
    return result;
}
项目:FastBanner    文件:IndicationView.java   
private Bitmap drawCircleBitmap(Bitmap bitmap) {
    Bitmap circleBitmap = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(circleBitmap);

    Paint paint = new Paint();
    paint.setDither(true);
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);

    canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, getMeasuredWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, 0, 0, paint);

    bitmap.recycle();

    return circleBitmap;
}
项目:sealtalk-android-master    文件:BitmapUtils.java   
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
                                        bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 12;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    if (null != bitmap) {
        bitmap.recycle();
        bitmap = null;
    }

    return output;
}
项目:PicShow-zhaipin    文件:XCRoundImageView.java   
/**
 * 获取圆形图片方法
 * @param bitmap
 * @param pixels
 * @return Bitmap
 * @author caizhiming
 */
private Bitmap getCircleBitmap(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;

    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    int x = bitmap.getWidth();

    canvas.drawCircle(x / 2, x / 2, x / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;


}
项目:XFrame    文件:XBitmapUtils.java   
/**
 * 合并Bitmap
 *
 * @param bgd 背景Bitmap
 * @param fg  前景Bitmap
 * @return 合成后的Bitmap
 */
public static Bitmap combineImages(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();

    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;
}
项目:android-mvp-interactor-architecture    文件:RoundedImageView.java   
private Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
    Bitmap finalBitmap;

    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) {
        finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
    } else {
        finalBitmap = bitmap;
    }

    Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
            finalBitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
            finalBitmap.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(finalBitmap.getWidth() / 2,
            finalBitmap.getHeight() / 2,
            finalBitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
}
项目:FlickLauncher    文件:BlurDrawable.java   
BlurDrawable(BlurWallpaperProvider provider, float radius, boolean allowTransparencyMode) {
    mProvider = provider;
    mRadius = radius;
    mAllowTransparencyMode = allowTransparencyMode;

    if (radius > 0) {
        mColorPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        mBlurPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
    }

    mDownsampleFactor = mProvider.getDownsampleFactor();
    initializeRenderScript(mProvider.getContext());
}
项目:showroom-android    文件:DecodeBitmapTask.java   
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float pixels, int width, int height) {
    final Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int sourceWidth = bitmap.getWidth();
    final int sourceHeight = bitmap.getHeight();

    float xScale = (float) width / bitmap.getWidth();
    float yScale = (float) height / bitmap.getHeight();
    float scale = Math.max(xScale, yScale);

    float scaledWidth = scale * sourceWidth;
    float scaledHeight = scale * sourceHeight;

    float left = (width - scaledWidth) / 2;
    float top = (height - scaledHeight) / 2;

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, width, height);
    final RectF rectF = new RectF(rect);

    final RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, pixels, pixels, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, null, targetRect, paint);

    return output;
}
项目:Barcode-Reader    文件:ScannerOverlay.java   
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // draw transparent rect
    int cornerRadius = 0;
    Paint eraser = new Paint();
    eraser.setAntiAlias(true);
    eraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));


    RectF rect = new RectF(left, top, dpToPx(rectWidth) + left, dpToPx(rectHeight) + top);
    canvas.drawRoundRect(rect, (float) cornerRadius, (float) cornerRadius, eraser);

    // draw horizontal line
    Paint line = new Paint();
    line.setColor(lineColor);
    line.setStrokeWidth(Float.valueOf(lineWidth));

    // draw the line to product animation
    if (endY >= top + dpToPx(rectHeight) + frames) {
        revAnimation = true;
    } else if (endY == top + frames) {
        revAnimation = false;
    }

    // check if the line has reached to bottom
    if (revAnimation) {
        endY -= frames;
    } else {
        endY += frames;
    }
    canvas.drawLine(left, endY, left + dpToPx(rectWidth), endY, line);
    invalidate();
}
项目:Mire    文件:NoiseEffect.java   
public NoiseEffect(Bitmap bitmap, int grainFPS, float scale) {
    super(bitmap, 0, 0);
    shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
    matrix = new Matrix();

    shader.setLocalMatrix(matrix);
    paint.setShader(shader);
    paint.setAlpha(144);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN));
    lastGrainOffset = System.currentTimeMillis();
    this.grainFPS = grainFPS;
    this.scale=scale;
}