use of android.graphics.PorterDuffXfermode in project LshUtils by SenhLinsh.
the class BitmapUtil method combineImagesToSameSize.
/**
* 合并Bitmap到相同大小
* @param bgd 后景Bitmap
* @param fg 前景Bitmap
* @return 合成后Bitmap
*/
public static Bitmap combineImagesToSameSize(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();
if (fg.getWidth() != width && fg.getHeight() != height) {
fg = zoom(fg, width, height);
}
if (bgd.getWidth() != width && bgd.getHeight() != height) {
bgd = zoom(bgd, width, height);
}
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;
}
use of android.graphics.PorterDuffXfermode in project LshUtils by SenhLinsh.
the class BitmapUtil method getRoundBitmap.
/** 转换图片成圆形 */
public static Bitmap getRoundBitmap(Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
float roundPx;
float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;
if (width <= height) {
roundPx = width / 2;
top = 0;
bottom = width;
left = 0;
right = width;
height = width;
dst_left = 0;
dst_top = 0;
dst_right = width;
dst_bottom = width;
} else {
roundPx = height / 2;
float clip = (width - height) / 2;
left = clip;
right = width - clip;
top = 0;
bottom = height;
width = height;
dst_left = 0;
dst_top = 0;
dst_right = height;
dst_bottom = height;
}
Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom);
final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom);
final RectF rectF = new RectF(dst);
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, src, dst, paint);
return output;
}
use of android.graphics.PorterDuffXfermode in project newsrob by marianokamp.
the class PreviewGenerator method getRoundedCornerBitmap.
private Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.drawARGB(0, 0, 0, 0);
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final int color = 0xffffffff;
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundedCornerRadiusPx, roundedCornerRadiusPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, 0, 0, paint);
return output;
}
use of android.graphics.PorterDuffXfermode in project android-app-common-tasks by multidots.
the class Common method getRoundedCornerBitmap.
/**
* Get Rounded cornered bitmap
*
* @param bitmap
* @param roundPixels
* @return
*/
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, @SuppressWarnings("SameParameterValue") int roundPixels) {
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) roundPixels, (float) roundPixels, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
use of android.graphics.PorterDuffXfermode in project Android-Bootstrap by Bearded-Hen.
the class BootstrapProgressBar method createRoundedBitmap.
/**
* Creates a rounded bitmap with transparent corners, from a square bitmap.
* See <a href="http://stackoverflow.com/questions/4028270">StackOverflow</a>
*
* @param bitmap the original bitmap
* @param cornerRadius the radius of the corners
* @param roundRight if you should round the corners on the right, note that if set to true and cornerRadius == 0 it will create a square
* @param roundLeft if you should round the corners on the right, note that if set to true and cornerRadius == 0 it will create a square
* @return a rounded bitmap
*/
private static Bitmap createRoundedBitmap(Bitmap bitmap, float cornerRadius, boolean roundRight, boolean roundLeft) {
Bitmap roundedBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), ARGB_8888);
Canvas canvas = new Canvas(roundedBitmap);
final Paint paint = new Paint();
final Rect frame = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
// final Rect frameLeft = new Rect(0, 0, bitmap.getWidth() /2, bitmap.getHeight());
// final Rect frameRight = new Rect(bitmap.getWidth() /2, bitmap.getHeight(), bitmap.getWidth(), bitmap.getHeight());
final Rect leftRect = new Rect(0, 0, bitmap.getWidth() / 2, bitmap.getHeight());
final Rect rightRect = new Rect(bitmap.getWidth() / 2, 0, bitmap.getWidth(), bitmap.getHeight());
// prepare canvas for transfer
paint.setAntiAlias(true);
paint.setColor(0xFFFFFFFF);
paint.setStyle(Paint.Style.FILL);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawRoundRect(new RectF(frame), cornerRadius, cornerRadius, paint);
if (!roundLeft) {
canvas.drawRect(leftRect, paint);
}
if (!roundRight) {
canvas.drawRect(rightRect, paint);
}
// draw bitmap
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, frame, frame, paint);
return roundedBitmap;
}
Aggregations