use of android.graphics.PorterDuffXfermode in project SmartCampus by Vegen.
the class EaseImageView method drawDrawable.
/**
* draw Rounded Rectangle
*
* @param canvas
* @param bitmap
*/
private void drawDrawable(Canvas canvas, Bitmap bitmap) {
Paint paint = new Paint();
paint.setColor(0xffffffff);
// smooths out the edges of what is being drawn
paint.setAntiAlias(true);
PorterDuffXfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
// set flags
int saveFlags = Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG;
canvas.saveLayer(0, 0, width, height, null, saveFlags);
if (shapeType == 1) {
canvas.drawCircle(width / 2, height / 2, width / 2 - 1, paint);
} else if (shapeType == 2) {
RectF rectf = new RectF(1, 1, getWidth() - 1, getHeight() - 1);
canvas.drawRoundRect(rectf, radius + 1, radius + 1, paint);
}
paint.setXfermode(xfermode);
float scaleWidth = ((float) getWidth()) / bitmap.getWidth();
float scaleHeight = ((float) getHeight()) / bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// bitmap scale
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
canvas.drawBitmap(bitmap, 0, 0, paint);
canvas.restore();
}
use of android.graphics.PorterDuffXfermode in project android-jigsaw-puzzle by julesbond007.
the class DrawingView method setErase.
/**
* Set erase to true when the erase button is clicked.
*
* @param isErase {@code true} if erase is clicked {@code false} otherwise
*/
public void setErase(boolean isErase) {
Xfermode xfermode = isErase ? new PorterDuffXfermode(PorterDuff.Mode.CLEAR) : null;
drawPaint.setXfermode(xfermode);
}
use of android.graphics.PorterDuffXfermode in project Offer by woshiyizhijiao.
the class ImageTools method createReflectionImageWithOrigin.
/**
* Base64 to byte[] //
*/
// public static byte[] base64ToBytes(String base64) throws IOException {
// byte[] bytes = Base64.decode(base64);
// return bytes;
// }
//
// /**
// * Byte[] to base64
// */
// public static String bytesTobase64(byte[] bytes) {
// String base64 = Base64.encode(bytes);
// return base64;
// }
/**
* Create reflection images
*
* @param bitmap
* @return
*/
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
final int reflectionGap = 4;
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, h / 2, w, h / 2, matrix, false);
Bitmap bitmapWithReflection = Bitmap.createBitmap(w, (h + h / 2), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmapWithReflection);
canvas.drawBitmap(bitmap, 0, 0, null);
Paint deafalutPaint = new Paint();
canvas.drawRect(0, h, w, h + reflectionGap, deafalutPaint);
canvas.drawBitmap(reflectionImage, 0, h + reflectionGap, null);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
paint.setShader(shader);
// Set the Transfer mode to be porter duff and destination in
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
// Draw a rectangle using the paint with our linear gradient
canvas.drawRect(0, h, w, bitmapWithReflection.getHeight() + reflectionGap, paint);
return bitmapWithReflection;
}
use of android.graphics.PorterDuffXfermode in project KISS by Neamar.
the class IconsHandler method generateBitmap.
private Drawable generateBitmap(Drawable defaultBitmap) {
// if no support images in the icon pack return the bitmap itself
if (backImages.size() == 0) {
return defaultBitmap;
}
// select a random background image
Random r = new Random();
int backImageInd = r.nextInt(backImages.size());
Bitmap backImage = backImages.get(backImageInd);
int w = backImage.getWidth();
int h = backImage.getHeight();
// create a bitmap for the result
Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
// draw the background first
canvas.drawBitmap(backImage, 0, 0, null);
// scale original icon
Bitmap scaledBitmap = Bitmap.createScaledBitmap(((BitmapDrawable) defaultBitmap).getBitmap(), (int) (w * factor), (int) (h * factor), false);
if (maskImage != null) {
// draw the scaled bitmap with mask
Bitmap mutableMask = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas maskCanvas = new Canvas(mutableMask);
maskCanvas.drawBitmap(maskImage, 0, 0, new Paint());
// paint the bitmap with mask into the result
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
canvas.drawBitmap(scaledBitmap, (w - scaledBitmap.getWidth()) / 2, (h - scaledBitmap.getHeight()) / 2, null);
canvas.drawBitmap(mutableMask, 0, 0, paint);
paint.setXfermode(null);
} else {
// draw the scaled bitmap without mask
canvas.drawBitmap(scaledBitmap, (w - scaledBitmap.getWidth()) / 2, (h - scaledBitmap.getHeight()) / 2, null);
}
// paint the front
if (frontImage != null) {
canvas.drawBitmap(frontImage, 0, 0, null);
}
return new BitmapDrawable(iconPackres, result);
}
use of android.graphics.PorterDuffXfermode in project android_frameworks_base by crdroidandroid.
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