android.graphics.PorterDuffXfermode Java Examples

The following examples show how to use android.graphics.PorterDuffXfermode. 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: X8MainPowerView.java    From FimiX8-RE with MIT License 7 votes vote down vote up
@SuppressLint({"WrongConstant"})
public void onDraw(Canvas canvas) {
    float src;
    super.onDraw(canvas);
    if (VERSION.SDK_INT <= 19) {
        this.mPaint.setColor(Color.argb(1, 0, 0, 0));
    }
    canvas.saveLayer(0.0f, 0.0f, (float) getWidth(), (float) getHeight(), null, 31);
    Rect dst = new Rect();
    dst.left = 0;
    dst.top = 0;
    dst.right = getWidth();
    dst.bottom = getHeight();
    canvas.drawBitmap(this.mBitmap, null, dst, null);
    this.mPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    if (this.percent == 0) {
        src = 1.0f;
    } else {
        src = (100.0f - (((((float) this.percent) / 100.0f) * 85.0f) + 15.0f)) / 100.0f;
    }
    canvas.drawRect(new Rect((int) (((float) getWidth()) - (((float) getWidth()) * src)), 0, getWidth(), getHeight()), this.mPaint);
    this.mPaint.setXfermode(null);
}
 
Example #2
Source File: Blockies.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
private 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.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);
    return output;
}
 
Example #3
Source File: BarcodeGraphicBase.java    From mlkit-material-android with Apache License 2.0 6 votes vote down vote up
BarcodeGraphicBase(GraphicOverlay overlay) {
  super(overlay);

  boxPaint = new Paint();
  boxPaint.setColor(ContextCompat.getColor(context, R.color.barcode_reticle_stroke));
  boxPaint.setStyle(Paint.Style.STROKE);
  boxPaint.setStrokeWidth(
      context.getResources().getDimensionPixelOffset(R.dimen.barcode_reticle_stroke_width));

  scrimPaint = new Paint();
  scrimPaint.setColor(ContextCompat.getColor(context, R.color.barcode_reticle_background));
  eraserPaint = new Paint();
  eraserPaint.setStrokeWidth(boxPaint.getStrokeWidth());
  eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

  boxCornerRadius =
      context.getResources().getDimensionPixelOffset(R.dimen.barcode_reticle_corner_radius);

  pathPaint = new Paint();
  pathPaint.setColor(Color.WHITE);
  pathPaint.setStyle(Paint.Style.STROKE);
  pathPaint.setStrokeWidth(boxPaint.getStrokeWidth());
  pathPaint.setPathEffect(new CornerPathEffect(boxCornerRadius));

  boxRect = PreferenceUtils.getBarcodeReticleBox(overlay);
}
 
Example #4
Source File: SwitchButton.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void draw(Canvas canvas) {
    super.draw(canvas);
    this.paint.setStyle(Style.STROKE);
    this.paint.setAntiAlias(true);
    float padding = AbViewUtil.dip2px(getContext(), 0.5f);
    this.rect.set(padding, padding, ((float) getWidth()) - padding, ((float) getHeight()) - padding);
    this.paint.setColor(603979775);
    this.paint.setStrokeWidth(AbViewUtil.dip2px(getContext(), 0.7f));
    canvas.drawRoundRect(this.rect, this.radius, this.radius, this.paint);
    this.paint.setStyle(Style.FILL);
    this.paint.setXfermode(new PorterDuffXfermode(Mode.SRC_OVER));
    this.rect.set((this.spotX - 1.0f) - this.radius, this.centerY - this.radius, (this.spotX + 1.1f) + this.radius, this.centerY + this.radius);
    this.paint.setColor(0);
    canvas.drawRoundRect(this.rect, this.radius, this.radius, this.paint);
    float spotR = ((float) this.spotSize) * 0.45f;
    this.rect.set(this.spotX - spotR, this.centerY - spotR, this.spotX + spotR, this.centerY + spotR);
    this.paint.setColor(this.spotColor);
    canvas.drawRoundRect(this.rect, spotR, spotR, this.paint);
}
 
Example #5
Source File: SemicircleView.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
private void initSource(int width, int height){
    //获取半径 * 曲率,曲率越大,半径越大
    float mRadius = getRadius(width, mDistanceTop) * mCurvature;
    //计算圆点
    float mStartX = (float) (width / 2);
    float mStartY = mDistanceTop - mRadius;

    Paint mPaint = new Paint();
    //遮罩圆形区域内颜色
    mPaint.setColor(maskInColor);
    mPaint.setAntiAlias(true);
    //显示相交部分
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

    //遮罩圆形区域外部
    mForeground = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    //遮罩圆形区域外部颜色
    mForeground.eraseColor(maskOutColor);

    Canvas mForeCanvas = new Canvas(mForeground);
    mForeCanvas.drawCircle(mStartX, mStartY, mRadius, mPaint);
}
 
Example #6
Source File: CommonUtil.java    From star-zone-android with Apache License 2.0 6 votes vote down vote up
public static Bitmap toRoundCorner(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 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(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
 
Example #7
Source File: AlphaOverlayTransformation.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override
public Bitmap transform(@NonNull Bitmap source) {

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setXfermode(new PorterDuffXfermode(preset.mode));
    paint.setColor(preset.color);
    paint.setAlpha(preset.alpha);

    Bitmap outBitmap = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(outBitmap);
    canvas.drawBitmap(source, 0, 0, null);
    canvas.drawRect(0, 0, outBitmap.getWidth(), outBitmap.getHeight(), paint);

    if (outBitmap != source && !source.isRecycled()) {
        source.recycle();
    }
    return outBitmap;
}
 
Example #8
Source File: CircularImageView.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
private Bitmap drawBevel(@NonNull Bitmap bitmap){
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();

    int radius = Math.min(h / 2 + (bevelStrokeWidth / 2), w / 2 + (bevelStrokeWidth / 2));
    Bitmap output = Bitmap.createBitmap(w + (bevelStrokeWidth * 2), h + (bevelStrokeWidth * 2), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(output);

    // Draw the source image (i.e., picture inside the circle)
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    c.drawARGB(0, 0, 0, 0);
    c.drawBitmap(bitmap, bevelStrokeWidth, bevelStrokeWidth, paint);

    // Draw the bevel around it
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(getResources().getColor(R.color.overlay_white_with_40));
    paint.setStrokeWidth(bevelStrokeWidth);
    c.drawCircle((w / 2) + bevelStrokeWidth, (h / 2) + bevelStrokeWidth, radius, paint);

    return output;
}
 
Example #9
Source File: CropImage.java    From Lassi-Android with MIT License 6 votes vote down vote up
/**
 * Create a new bitmap that has all pixels beyond the oval shape transparent. Old bitmap is
 * recycled.
 */
public static Bitmap toOvalBitmap(@NonNull Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    int color = 0xff424242;
    Paint paint = new Paint();

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

    RectF rect = new RectF(0, 0, width, height);
    canvas.drawOval(rect, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, 0, 0, paint);

    bitmap.recycle();

    return output;
}
 
Example #10
Source File: ShadowDrawable.java    From ShadowDrawable with MIT License 6 votes vote down vote up
private ShadowDrawable(int shape, int[] bgColor, int shapeRadius, int shadowColor, int shadowRadius, int offsetX, int offsetY) {
	this.mShape = shape;
	this.mBgColor = bgColor;
	this.mShapeRadius = shapeRadius;
	this.mShadowRadius = shadowRadius;
	this.mOffsetX = offsetX;
	this.mOffsetY = offsetY;

	mShadowPaint = new Paint();
	mShadowPaint.setColor(Color.TRANSPARENT);
	mShadowPaint.setAntiAlias(true);
	mShadowPaint.setShadowLayer(shadowRadius, offsetX, offsetY, shadowColor);
	mShadowPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));

	mBgPaint = new Paint();
	mBgPaint.setAntiAlias(true);
}
 
Example #11
Source File: CropImageView.java    From YImagePicker with Apache License 2.0 6 votes vote down vote up
private Bitmap createCircleBitmap(Bitmap resource, int backgroundColor) {
    int width = resource.getWidth();
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    Bitmap circleBitmap = Bitmap.createBitmap(resource.getWidth(), resource.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(circleBitmap);
    if (backgroundColor != Color.TRANSPARENT) {
        paint.setColor(backgroundColor);
    }
    canvas.drawCircle(width / 2, width / 2, width / 2, paint);
    //设置画笔为取交集模式
    if (backgroundColor == Color.TRANSPARENT) {
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    } else {
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
    }

    //裁剪图片
    canvas.drawBitmap(resource, 0, 0, paint);
    return circleBitmap;
}
 
Example #12
Source File: Service.java    From Twire with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a bitmap with rounded corners.
 *
 * @param bitmap The bitmap
 * @param i      the corner radius in pixels
 * @return The bitmap with rounded corners
 */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int i) {
    if (bitmap == null) {
        return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    }

    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());
    final RectF rectF = new RectF(rect);

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

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

    return output;
}
 
Example #13
Source File: ClipImageView.java    From Tok-Android with GNU General Public License v3.0 6 votes vote down vote up
public void drawRectangleOrCircle(Canvas canvas) {
    Bitmap bitmap =
        Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas temp = new Canvas(bitmap);
    Paint transparentPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    PorterDuffXfermode porterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
    transparentPaint.setColor(Color.TRANSPARENT);
    temp.drawRect(0, 0, temp.getWidth(), temp.getHeight(), mPaint);
    transparentPaint.setXfermode(porterDuffXfermode);
    if (mDrawCircleFlag) {
        float cx = mClipBorder.left + mClipBorder.width() / 2f;
        float cy = mClipBorder.top + mClipBorder.height() / 2f;
        float radius = mClipBorder.height() / 2f;
        temp.drawCircle(cx, cy, radius, transparentPaint);
    } else {
        RectF rectF =
            new RectF(mClipBorder.left, mClipBorder.top, mClipBorder.right, mClipBorder.bottom);
        temp.drawRoundRect(rectF, mRoundCorner, mRoundCorner, transparentPaint);
    }
    canvas.drawBitmap(bitmap, 0, 0, null);
}
 
Example #14
Source File: BrushDrawingViewApiTest.java    From PhotoEditor with MIT License 6 votes vote down vote up
@Test
public void testDefaultPaintAttributes() {
    BrushDrawingView brushDrawingView = new BrushDrawingView(mContext);
    Paint drawingPaint = brushDrawingView.getDrawingPaint();

    assertEquals(drawingPaint.getColor(), Color.BLACK);
    assertEquals(drawingPaint.getStyle(), Paint.Style.STROKE);
    assertEquals(drawingPaint.getStrokeJoin(), Paint.Join.ROUND);
    assertEquals(drawingPaint.getStrokeCap(), Paint.Cap.ROUND);
    assertEquals(drawingPaint.getStrokeWidth(), BrushDrawingView.DEFAULT_BRUSH_SIZE);
    assertEquals(drawingPaint.getAlpha(), BrushDrawingView.DEFAULT_OPACITY);
    assertTrue(drawingPaint.getXfermode() instanceof PorterDuffXfermode);

    // Spy is not working properly
    /*Paint spyPaint = Mockito.spy(drawingPaint);
    verify(spyPaint, times(1)).setColor(Color.BLACK);*/
}
 
Example #15
Source File: BitmapUtil.java    From timecat with Apache License 2.0 6 votes vote down vote up
/**
 * 根据原图和变长绘制圆形图片
 *
 * @param source
 * @param min
 *
 * @return
 */
public static Bitmap createCircleImage(Bitmap source, int min) {
    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    Bitmap target = Bitmap.createBitmap(min, min, Bitmap.Config.ARGB_8888);
    /**
     * 产生一个同样大小的画布
     */
    Canvas canvas = new Canvas(target);
    /**
     * 首先绘制圆形
     */
    canvas.drawCircle(min / 2, min / 2, min / 2, paint);
    /**
     * 使用SRC_IN
     */
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    /**
     * 绘制图片
     */
    canvas.drawBitmap(source, 0, 0, paint);
    return target;
}
 
Example #16
Source File: ImageUtils.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
/**
 * 将图片剪裁为圆形
 */
static Bitmap createCircleImage(Bitmap source) {
    if (source == null) {
        return null;
    }

    int length = Math.min(source.getWidth(), source.getHeight());
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    Bitmap target = Bitmap.createBitmap(length, length, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(target);
    canvas.drawCircle(source.getWidth() / 2, source.getHeight() / 2, length / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(source, 0, 0, paint);
    return target;
}
 
Example #17
Source File: DvbParser.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct an instance for the given subtitle and ancillary page ids.
 *
 * @param subtitlePageId The id of the subtitle page carrying the subtitle to be parsed.
 * @param ancillaryPageId The id of the ancillary page containing additional data.
 */
public DvbParser(int subtitlePageId, int ancillaryPageId) {
  defaultPaint = new Paint();
  defaultPaint.setStyle(Paint.Style.FILL_AND_STROKE);
  defaultPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
  defaultPaint.setPathEffect(null);
  fillRegionPaint = new Paint();
  fillRegionPaint.setStyle(Paint.Style.FILL);
  fillRegionPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
  fillRegionPaint.setPathEffect(null);
  canvas = new Canvas();
  defaultDisplayDefinition = new DisplayDefinition(719, 575, 0, 719, 0, 575);
  defaultClutDefinition = new ClutDefinition(0, generateDefault2BitClutEntries(),
      generateDefault4BitClutEntries(), generateDefault8BitClutEntries());
  subtitleService = new SubtitleService(subtitlePageId, ancillaryPageId);
}
 
Example #18
Source File: CropImage.java    From timecat with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new bitmap that has all pixels beyond the oval shape transparent.
 * Old bitmap is recycled.
 */
public static Bitmap toOvalBitmap(@NonNull Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    int color = 0xff424242;
    Paint paint = new Paint();

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

    RectF rect = new RectF(0, 0, width, height);
    canvas.drawOval(rect, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, 0, 0, paint);

    bitmap.recycle();

    return output;
}
 
Example #19
Source File: ImageHelper.java    From android-auto-call-recorder with MIT License 6 votes vote down vote up
public Bitmap getRoundedCornerBitmap(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 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, (float) pixels, (float) pixels, paint);

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

    return output;
}
 
Example #20
Source File: RoundAngleImageView.java    From wallpaper with GNU General Public License v2.0 6 votes vote down vote up
private void init(Context context, AttributeSet attrs) {

		if (attrs != null) {
			TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundAngleImageView);
			roundWidth = a.getDimensionPixelSize(R.styleable.RoundAngleImageView_roundWidth, roundWidth);
			roundHeight = a.getDimensionPixelSize(R.styleable.RoundAngleImageView_roundHeight, roundHeight);
		} else {
			float density = context.getResources().getDisplayMetrics().density;
			roundWidth = (int) (roundWidth * density);
			roundHeight = (int) (roundHeight * density);
		}

		paint = new Paint();
		paint.setColor(Color.WHITE);
		paint.setAntiAlias(true);
		paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));

		paint2 = new Paint();
		paint2.setXfermode(null);
	}
 
Example #21
Source File: RoundAngleImageView.java    From wallpaper with GNU General Public License v2.0 6 votes vote down vote up
private void init(Context context, AttributeSet attrs) {

		if (attrs != null) {
			TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundAngleImageView);
			roundWidth = a.getDimensionPixelSize(R.styleable.RoundAngleImageView_roundWidth, roundWidth);
			roundHeight = a.getDimensionPixelSize(R.styleable.RoundAngleImageView_roundHeight, roundHeight);
		} else {
			float density = context.getResources().getDisplayMetrics().density;
			roundWidth = (int) (roundWidth * density);
			roundHeight = (int) (roundHeight * density);
		}

		paint = new Paint();
		paint.setColor(Color.WHITE);
		paint.setAntiAlias(true);
		paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));

		paint2 = new Paint();
		paint2.setXfermode(null);
	}
 
Example #22
Source File: ThermometerView.java    From ThermometerView with MIT License 6 votes vote down vote up
/**
 * 绘制温度计水银高度
 * 注:须与{@link #drawShape(Paint, Canvas)}方法结合
 *
 * @param shapePaint Paint
 * @param canvas     Canvas
 */
private void drawWaveShape(Paint shapePaint, Canvas canvas) {
    float waveTop = mPaddingTop + titleHeight + minThermometerRadius
            + (maxScaleValue - curScaleValue) * 10 * scaleSpaceHeight;

    shapePaint.setColor(leftMercuryColor);
    shapePaint.clearShadowLayer();
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));

    canvas.drawRect(leftWaveLeft, waveTop, leftWaveRight, waveBottom, shapePaint);

    shapePaint.setColor(rightMercuryColor);
    shapePaint.clearShadowLayer();

    canvas.drawRect(rightWaveLeft, waveTop, rightWaveRight, waveBottom, shapePaint);
}
 
Example #23
Source File: ShareLocationActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
Bitmap getBitmapWithId(String id) {
    if (userGravatar.containsKey(id) && userGravatar.get(id) != null){
        return userGravatar.get(id);
    }
    UserVCard vCard = ProfileUtils.getLocalVCard(id);
    if (!TextUtils.isEmpty(vCard.gravantarUrl)) {
        String filePath = MyDiskCache.getSmallFile(QtalkStringUtils.getGravatar(vCard.gravantarUrl,
                true)).getAbsolutePath();
        Bitmap bmp = BitmapFactory.decodeFile(filePath);
        if(bmp!=null) {
            int width = bmp.getWidth();
            Bitmap resultBmp = Bitmap.createBitmap(width, width,
                    Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(resultBmp);
            Paint paint = new Paint();
            canvas.drawCircle(width / 2.0f, width / 2.0f, width / 2.0f, paint);
            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
            canvas.drawBitmap(bmp, 0, 0, paint);
            bmp.recycle();
            userGravatar.put(id, resultBmp);
            return resultBmp;
        }
    }
    return null;
}
 
Example #24
Source File: DonutProgress.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
public DonutProgress(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    arcPaint = new Paint();
    arcPaint.setColor(Color.WHITE);
    arcPaint.setAntiAlias(true);

    textPaint = new Paint();
    textPaint.setColor(Color.WHITE);
    textPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, getResources().getDisplayMetrics()));
    FontsManager.set(getContext(), textPaint, R.font.roboto_light);
    textPaint.setAntiAlias(true);

    transparentPaint = new Paint();
    transparentPaint.setColor(Color.TRANSPARENT);
    transparentPaint.setAlpha(0xFF);
    transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

    padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());

    if (isInEditMode())
        setProgress(new Random().nextInt(100));
    else
        setProgress(0);
}
 
Example #25
Source File: BitmapUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 合并图片
 * @param bgd      后景 Bitmap
 * @param fg       前景 Bitmap
 * @param mode     合并模式 {@link PorterDuff.Mode}
 * @param bgdPoint 后景绘制 left、top 坐标
 * @param fgPoint  前景绘制 left、top 坐标
 * @return 合并后的图片
 */
public static Bitmap combine(final Bitmap bgd, final Bitmap fg, final PorterDuff.Mode mode, final Point bgdPoint, final Point fgPoint) {
    if (isEmpty(bgd) || isEmpty(fg)) return null;

    int width = bgd.getWidth() > fg.getWidth() ? bgd.getWidth() : fg.getWidth();
    int height = bgd.getHeight() > fg.getHeight() ? bgd.getHeight() : fg.getHeight();

    Paint paint = new Paint();
    if (mode != null) {
        paint.setXfermode(new PorterDuffXfermode(mode));
    }

    Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    canvas.drawBitmap(bgd, (bgdPoint != null) ? bgdPoint.x : 0, (bgdPoint != null) ? bgdPoint.y : 0, null);
    canvas.drawBitmap(fg, (fgPoint != null) ? fgPoint.x : 0, (fgPoint != null) ? fgPoint.y : 0, paint);
    return newBitmap;
}
 
Example #26
Source File: BitmapUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 图片圆角处理 ( 非圆形 )
 * @param bitmap 待操作源图片
 * @param pixels 圆角大小
 * @return 圆角处理后的图片
 */
public static Bitmap roundCorner(final Bitmap bitmap, final float pixels) {
    if (isEmpty(bitmap)) return null;
    // 创建一个同源图片一样大小的矩形, 用于把源图片绘制到这个矩形上
    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    RectF rectF = new RectF(rect); // 创建一个精度更高的矩形, 用于画出圆角效果

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(0xff424242); // 设置画笔的颜色为不透明的灰色

    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawRoundRect(rectF, pixels, pixels, paint);
    // 绘制底圆后, 进行合并 ( 交集处理 )
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return newBitmap;
}
 
Example #27
Source File: BrushDrawingViewApiTest.java    From PhotoEditor with MIT License 6 votes vote down vote up
@Test
public void testPaintAttributesAfterBrushModeIsEnabled() {
    BrushDrawingView brushDrawingView = new BrushDrawingView(mContext);
    brushDrawingView.setBrushDrawingMode(true);
    Paint drawingPaint = brushDrawingView.getDrawingPaint();

    assertEquals(drawingPaint.getStyle(), Paint.Style.STROKE);
    assertEquals(drawingPaint.getStrokeJoin(), Paint.Join.ROUND);
    assertEquals(drawingPaint.getStrokeCap(), Paint.Cap.ROUND);
    assertEquals(drawingPaint.getStrokeWidth(), BrushDrawingView.DEFAULT_BRUSH_SIZE);
    assertEquals(drawingPaint.getAlpha(), BrushDrawingView.DEFAULT_OPACITY);
    assertTrue(drawingPaint.getXfermode() instanceof PorterDuffXfermode);

    Paint spyPaint = Mockito.spy(drawingPaint);
    verify(spyPaint, times(0)).setColor(Color.BLACK);
}
 
Example #28
Source File: ImageHelper.java    From Doctorave with MIT License 6 votes vote down vote up
public static Bitmap getRoundedCornerBitmap(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;
}
 
Example #29
Source File: ViewUtils.java    From FirefoxReality with Mozilla Public License 2.0 6 votes vote down vote up
@NonNull
public static Bitmap getRoundedCroppedBitmap(@NonNull Bitmap bitmap) {
    int widthLight = bitmap.getWidth();
    int heightLight = bitmap.getHeight();

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

    Canvas canvas = new Canvas(output);
    Paint paintColor = new Paint();
    paintColor.setFlags(Paint.ANTI_ALIAS_FLAG);

    RectF rectF = new RectF(new Rect(0, 0, widthLight, heightLight));

    canvas.drawRoundRect(rectF, widthLight / 2 ,heightLight / 2,paintColor);

    Paint paintImage = new Paint();
    paintImage.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
    canvas.drawBitmap(bitmap, 0, 0, paintImage);

    return output;
}
 
Example #30
Source File: CircleImageView.java    From V2EX with GNU General Public License v3.0 6 votes vote down vote up
private Bitmap getCircleBitmap(Bitmap bitmap) {

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

        Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        mPaint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        int x = bitmap.getWidth();

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