use of android.graphics.PorterDuffXfermode in project plaid by nickbutcher.
the class CutoutTextView method createBitmap.
private void createBitmap() {
if (cutout != null && !cutout.isRecycled()) {
cutout.recycle();
}
cutout = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
cutout.setHasAlpha(true);
Canvas cutoutCanvas = new Canvas(cutout);
cutoutCanvas.drawColor(foregroundColor);
// this is the magic – Clear mode punches out the bitmap
textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
cutoutCanvas.drawText(text, textX, textY, textPaint);
}
use of android.graphics.PorterDuffXfermode in project mobile-android by photo.
the class ImageResizer method getRoundedCornerBitmap.
/**
* Get the bitmap with rounded corners. Taken from here
* http://stackoverflow.com/a/3292810/527759
*
* @param bitmap - bitmap to add corners to
* @param pixels - corner radius
* @return
*/
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;
}
use of android.graphics.PorterDuffXfermode in project glitch-hq-android by tinyspeck.
the class BitmapUtil method MultiplyPaint.
public static void MultiplyPaint(Canvas cvs, Paint paint, Bitmap bmMask) {
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
cvs.drawBitmap(bmMask, 0, 0, paint);
}
use of android.graphics.PorterDuffXfermode in project RippleEffect by traex.
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 Ushahidi_Android by ushahidi.
the class PhotoUtils method getRoundedCornerBitmap.
/**
* Create rounded corner bitmap from original bitmap.
* <p>
* Reference
* http://stackoverflow.com/questions/2459916/how-to-make-an-imageview
* -to-have-rounded-corners
*
* @param input
* Original bitmap.
* @param cornerRadius
* Corner radius in pixel.
* @param w
* @param h
* @param squareTL
* @param squareTR
* @param squareBL
* @param squareBR
* @return
*/
public static Bitmap getRoundedCornerBitmap(Bitmap input, float cornerRadius, int w, int h, boolean squareTL, boolean squareTR, boolean squareBL, boolean squareBR) {
Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, w, h);
final RectF rectF = new RectF(rect);
// make sure that our rounded corner is scaled appropriately
final float roundPx = cornerRadius;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
// draw rectangles over the corners we want to be squared
if (squareTL) {
canvas.drawRect(0, 0, w / 2, h / 2, paint);
}
if (squareTR) {
canvas.drawRect(w / 2, 0, w, h / 2, paint);
}
if (squareBL) {
canvas.drawRect(0, h / 2, w / 2, h, paint);
}
if (squareBR) {
canvas.drawRect(w / 2, h / 2, w, h, paint);
}
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(input, 0, 0, paint);
return output;
}
Aggregations