use of android.graphics.PorterDuffXfermode in project ABPlayer by winkstu.
the class BitmapHelper method getRoundedCornerBitmap.
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float radius) {
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);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, radius, radius, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
use of android.graphics.PorterDuffXfermode in project wire-android by wireapp.
the class BitmapUtils method getVignetteBitmap.
/**
* Helper function to create a bitmap that serves as a vignette overlay.
*
* @return
*/
public static Bitmap getVignetteBitmap(Resources resources) {
double radiusFactor = ResourceUtils.getResourceFloat(resources, R.dimen.background__vignette_radius_factor);
int radius = (int) (VIGNETTE_WIDTH * radiusFactor);
int baseColor = resources.getColor(R.color.black_80);
int colorCenter = resources.getColor(R.color.black);
int colorEdge = resources.getColor(R.color.transparent);
Bitmap dest = Bitmap.createBitmap(VIGNETTE_WIDTH, VIGNETTE_HEIGHT, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(dest);
Bitmap tempBitmap = Bitmap.createBitmap(dest.getWidth(), dest.getHeight(), Bitmap.Config.ARGB_8888);
Canvas tempCanvas = new Canvas(tempBitmap);
tempCanvas.drawColor(baseColor);
RadialGradient gradient = new RadialGradient(VIGNETTE_WIDTH / 2, VIGNETTE_HEIGHT / 2, radius, colorCenter, colorEdge, android.graphics.Shader.TileMode.CLAMP);
Paint p = new Paint();
p.setShader(gradient);
p.setColor(0xFF000000);
p.setAntiAlias(true);
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
tempCanvas.drawCircle(VIGNETTE_WIDTH / 2, VIGNETTE_HEIGHT / 2, radius, p);
canvas.drawBitmap(tempBitmap, 0, 0, null);
return dest;
}
use of android.graphics.PorterDuffXfermode in project teaTime by ancfdy.
the class ScratchCard method initPaint.
private void initPaint() {
paint = new Paint();
paint.setAlpha(0);
//在已有的图像上绘图将会在其上面添加一层新的图层,如果新图层的paint是不透明的,那么它将遮挡住下面的paint;
//如果新图层它是部分透明的,那么它不透明的地方将会被染上下面的颜色
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
paint.setStyle(Paint.Style.STROKE);
//设置笔触和连接处能更加圆滑
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeWidth(60);
path = new Path();
bgBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.img_loading);
fgBitmap = Bitmap.createBitmap(bgBitmap.getWidth(), bgBitmap.getHeight(), Bitmap.Config.ARGB_8888);
canvas = new Canvas(fgBitmap);
//在图层上绘制一层颜色
canvas.drawColor(Color.parseColor("#1dcdef"));
}
use of android.graphics.PorterDuffXfermode in project Lightning-Browser by anthonycr.
the class DrawableUtils method getRoundedNumberImage.
public static Bitmap getRoundedNumberImage(int number, int width, int height, int color, int thickness) {
String text;
if (number > 99) {
text = "∞";
} else {
text = String.valueOf(number);
}
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
Paint paint = new Paint();
paint.setColor(color);
Typeface boldText = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
paint.setTypeface(boldText);
paint.setTextSize(Utils.dpToPx(14));
paint.setAntiAlias(true);
paint.setTextAlign(Paint.Align.CENTER);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
int radius = Utils.dpToPx(2);
RectF outer = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
canvas.drawRoundRect(outer, radius, radius, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
radius--;
RectF inner = new RectF(thickness, thickness, canvas.getWidth() - thickness, canvas.getHeight() - thickness);
canvas.drawRoundRect(inner, radius, radius, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
int xPos = (canvas.getWidth() / 2);
int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));
canvas.drawText(String.valueOf(text), xPos, yPos, paint);
return image;
}
use of android.graphics.PorterDuffXfermode in project TapTargetView by KeepSafe.
the class TapTargetView method applyTargetOptions.
protected void applyTargetOptions(Context context) {
shouldTintTarget = target.tintTarget;
shouldDrawShadow = target.drawShadow;
cancelable = target.cancelable;
if (shouldDrawShadow && Build.VERSION.SDK_INT >= 21) {
outlineProvider = new ViewOutlineProvider() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void getOutline(View view, Outline outline) {
if (outerCircleCenter == null)
return;
outline.setOval((int) (outerCircleCenter[0] - outerCircleRadius), (int) (outerCircleCenter[1] - outerCircleRadius), (int) (outerCircleCenter[0] + outerCircleRadius), (int) (outerCircleCenter[1] + outerCircleRadius));
outline.setAlpha(outerCircleAlpha / 255.0f);
if (Build.VERSION.SDK_INT >= 22) {
outline.offset(0, SHADOW_DIM);
}
}
};
setOutlineProvider(outlineProvider);
setElevation(SHADOW_DIM);
}
if ((shouldDrawShadow && outlineProvider == null) || Build.VERSION.SDK_INT < 18) {
setLayerType(LAYER_TYPE_SOFTWARE, null);
} else {
setLayerType(LAYER_TYPE_HARDWARE, null);
}
final Resources.Theme theme = context.getTheme();
isDark = UiUtil.themeIntAttr(context, "isLightTheme") == 0;
final Integer outerCircleColor = target.outerCircleColorInt(context);
if (outerCircleColor != null) {
outerCirclePaint.setColor(outerCircleColor);
} else if (theme != null) {
outerCirclePaint.setColor(UiUtil.themeIntAttr(context, "colorPrimary"));
} else {
outerCirclePaint.setColor(Color.WHITE);
}
final Integer targetCircleColor = target.targetCircleColorInt(context);
if (targetCircleColor != null) {
targetCirclePaint.setColor(targetCircleColor);
} else {
targetCirclePaint.setColor(isDark ? Color.BLACK : Color.WHITE);
}
if (target.transparentTarget) {
targetCirclePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
targetCirclePulsePaint.setColor(targetCirclePaint.getColor());
final Integer targetDimColor = target.dimColorInt(context);
if (targetDimColor != null) {
dimColor = UiUtil.setAlpha(targetDimColor, 0.3f);
} else {
dimColor = -1;
}
final Integer titleTextColor = target.titleTextColorInt(context);
if (titleTextColor != null) {
titlePaint.setColor(titleTextColor);
} else {
titlePaint.setColor(isDark ? Color.BLACK : Color.WHITE);
}
final Integer descriptionTextColor = target.descriptionTextColorInt(context);
if (descriptionTextColor != null) {
descriptionPaint.setColor(descriptionTextColor);
} else {
descriptionPaint.setColor(titlePaint.getColor());
}
if (target.typeface != null) {
titlePaint.setTypeface(target.typeface);
descriptionPaint.setTypeface(target.typeface);
}
}
Aggregations