use of android.graphics.PorterDuffXfermode in project UltimateAndroid by cymcsg.
the class RippleView method getCircleBitmap.
private Bitmap getCircleBitmap(final int radius) {
final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect((int) (x - radius), (int) (y - radius), (int) (x + radius), (int) (y + radius));
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawCircle(x, y, radius, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(originBitmap, rect, rect, paint);
return output;
}
use of android.graphics.PorterDuffXfermode in project Android-Image-Cropper by ArthurHub.
the class CropImage method toOvalBitmap.
/**
* 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;
}
use of android.graphics.PorterDuffXfermode in project android-bootstrap by AndroidBootstrap.
the class ImageUtils method roundCorners.
/**
* Round the corners of a {@link Bitmap}
*
* @param source
* @param radius
* @return rounded corner bitmap
*/
public static Bitmap roundCorners(final Bitmap source, final float radius) {
final int width = source.getWidth();
final int height = source.getHeight();
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(WHITE);
final Bitmap clipped = Bitmap.createBitmap(width, height, ARGB_8888);
Canvas canvas = new Canvas(clipped);
canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius, paint);
paint.setXfermode(new PorterDuffXfermode(DST_IN));
final Bitmap rounded = Bitmap.createBitmap(width, height, ARGB_8888);
canvas = new Canvas(rounded);
canvas.drawBitmap(source, 0, 0, null);
canvas.drawBitmap(clipped, 0, 0, paint);
source.recycle();
clipped.recycle();
return rounded;
}
use of android.graphics.PorterDuffXfermode in project Notes by Elder-Wu.
the class GuaGuaKa method onDraw.
@Override
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(backBitmap, 0, 0, null);
pathPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
cacheCanvas.drawPath(path, pathPaint);
canvas.drawBitmap(cacheBitmap, 0, 0, null);
}
use of android.graphics.PorterDuffXfermode in project android_frameworks_base by DirtyUnicorns.
the class UserIconDrawable method setBadge.
public UserIconDrawable setBadge(Drawable badge) {
mBadge = badge;
if (mBadge != null) {
if (mClearPaint == null) {
mClearPaint = new Paint();
mClearPaint.setAntiAlias(true);
mClearPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
mClearPaint.setStyle(Paint.Style.FILL);
}
// update metrics
onBoundsChange(getBounds());
} else {
invalidateSelf();
}
return this;
}
Aggregations