本文整理汇总了Java中android.graphics.Paint.setXfermode方法的典型用法代码示例。如果您正苦于以下问题:Java Paint.setXfermode方法的具体用法?Java Paint.setXfermode怎么用?Java Paint.setXfermode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Paint
的用法示例。
在下文中一共展示了Paint.setXfermode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRoundedCornerBitmap
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* Creates a bitmap with rounded corners.
* @param bitmap The bitmap
* @param i the corner radius in pixels
* @return The bitmap with rounded corners
*/
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int i) {
if (bitmap == null) {
return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
}
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) i, (float) i, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
示例2: init
import android.graphics.Paint; //导入方法依赖的package包/类
private void init(Context context) {
setWillNotDraw(false);
setVisibility(INVISIBLE);
lineStroke = Utils.dpToPx(4);
isReady = false;
isRevealAnimationEnabled = true;
dismissOnTouch = false;
isPerformClick = false;
enableDismissAfterShown = false;
dismissOnBackPress = false;
handler = new Handler();
preferencesManager = new PreferencesManager(context);
eraser = new Paint();
eraser.setColor(0xFFFFFFFF);
eraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
eraser.setFlags(Paint.ANTI_ALIAS_FLAG);
}
示例3: getRoundedCornerBitmap
import android.graphics.Paint; //导入方法依赖的package包/类
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
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(0xff424242);
canvas.drawRoundRect(rectF, pixels, pixels, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
示例4: createFramedPhoto
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* @param x 图像的宽度
* @param y 图像的高度
* @param image 源图片
* @param outerRadiusRat 圆角的大小
* @return 圆角图片
*/
public static Bitmap createFramedPhoto(int x, int y, Bitmap image, float outerRadiusRat) {
// 根据源文件新建一个darwable对象
Drawable imageDrawable = new BitmapDrawable(image);
// 新建一个新的输出图片
Bitmap output = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
// 新建一个矩形
RectF outerRect = new RectF(0, 0, x, y);
// 产生一个红色的圆角矩形
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.RED);
canvas.drawRoundRect(outerRect, outerRadiusRat, outerRadiusRat, paint);
// 将源图片绘制到这个圆角矩形上
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
imageDrawable.setBounds(0, 0, x, y);
canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG);
imageDrawable.draw(canvas);
canvas.restore();
return output;
}
示例5: toRoundCorner
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* 转为圆角图片
*
* @param src 源图片
* @param radius 圆角的度数
* @param recycle 是否回收
* @return 圆角图片
*/
public static Bitmap toRoundCorner(Bitmap src, float radius, boolean recycle) {
if (null == src) return null;
int width = src.getWidth();
int height = src.getHeight();
Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
Paint paint = new Paint();
Canvas canvas = new Canvas(ret);
Rect rect = new Rect(0, 0, width, height);
paint.setAntiAlias(true);
canvas.drawRoundRect(new RectF(rect), radius, radius, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(src, rect, rect, paint);
if (recycle && !src.isRecycled()) src.recycle();
return ret;
}
示例6: getRoundedCornerBitmap
import android.graphics.Paint; //导入方法依赖的package包/类
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
if (bitmap == null) {
return null;
}
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, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
示例7: init
import android.graphics.Paint; //导入方法依赖的package包/类
private void init(Context context, AttributeSet attrs) {
mask = BitmapFactory.decodeResource(context.getResources(), R.drawable.face_mask);
rect = BitmapFactory.decodeResource(context.getResources(), R.drawable.face_rect);
leftScan = BitmapFactory.decodeResource(context.getResources(), R.drawable.up_left_scan);
rightScan = BitmapFactory.decodeResource(context.getResources(), R.drawable.up_right_scan);
faceW = mask.getWidth();
faceH = mask.getHeight();
paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.parseColor("#4C0C0F3C"));
paint1 = new Paint();
paint1.setAntiAlias(true);
paint1.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
paint2 = new Paint();
paint2.setAntiAlias(true);
paint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
paint3 = new Paint();
paint3.setAntiAlias(true);
paint3.setColor(Color.parseColor("#000000"));
}
示例8: toRound
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* 转为圆形图片
*
* @param src 源图片
* @param recycle 是否回收
* @return 圆形图片
*/
public static Bitmap toRound(Bitmap src, boolean recycle) {
if (isEmptyBitmap(src)) return null;
int width = src.getWidth();
int height = src.getHeight();
int radius = Math.min(width, height) >> 1;
Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
Paint paint = new Paint();
Canvas canvas = new Canvas(ret);
Rect rect = new Rect(0, 0, width, height);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawCircle(width >> 1, height >> 1, radius, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(src, rect, rect, paint);
if (recycle && !src.isRecycled()) src.recycle();
return ret;
}
示例9: makeRoundCornerBitmap
import android.graphics.Paint; //导入方法依赖的package包/类
public static Bitmap makeRoundCornerBitmap(Bitmap bitmap, int pixels, int color) {
Bitmap outputBitmap = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(outputBitmap);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
RectF rectF = new RectF(rect);
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(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return outputBitmap;
}
示例10: setupDonePaints
import android.graphics.Paint; //导入方法依赖的package包/类
private void setupDonePaints() {
doneBgPaint = new Paint();
doneBgPaint.setAntiAlias(true);
doneBgPaint.setStyle(Paint.Style.FILL);
doneBgPaint.setColor(0xff39cb72);
checkmarkPaint = new Paint();
maskPaint = new Paint();
maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
}
示例11: getRoundedCornerBitmap
import android.graphics.Paint; //导入方法依赖的package包/类
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float pixels, int width, int height) {
final Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(output);
final int sourceWidth = bitmap.getWidth();
final int sourceHeight = bitmap.getHeight();
float xScale = (float) width / bitmap.getWidth();
float yScale = (float) height / bitmap.getHeight();
float scale = Math.max(xScale, yScale);
float scaledWidth = scale * sourceWidth;
float scaledHeight = scale * sourceHeight;
float left = (width - scaledWidth) / 2;
float top = (height - scaledHeight) / 2;
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, width, height);
final RectF rectF = new RectF(rect);
final RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, pixels, pixels, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, null, targetRect, paint);
return output;
}
示例12: getCircleBitmap
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* 生成透明背景的圆形图片
*/
public static Bitmap getCircleBitmap(Bitmap bitmap) {
if (bitmap == null) {
return null;
}
try {
Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(circleBitmap);
final Paint paint = new Paint();
paint.setAntiAlias(true);
float radius = Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2.0f;
//绘制透明底
canvas.drawARGB(0, 0, 0, 0);
//绘制背景圆
paint.setColor(Color.WHITE);
canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, radius, paint);
//取两层绘制交集。显示上层。
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
//绘制图片并取交集,显示上层
//取中间区域绘制
int left = (int) ((bitmap.getWidth() - radius * 2) / 2);
int top = (int) ((bitmap.getHeight() - radius * 2) / 2);
canvas.drawBitmap(bitmap, -left, -top, paint);
bitmap.recycle();
bitmap = null;
return circleBitmap;
} catch (Exception e) {
return bitmap;
}
}
示例13: dispatchDraw
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
protected void dispatchDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(defaultColor);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
canvas.drawCircle(mCenterX, mCenterY, mRadius, paint);
super.dispatchDraw(canvas);
}
示例14: BezelImageView
import android.graphics.Paint; //导入方法依赖的package包/类
public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// Attribute initialization.
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView,
defStyle, 0);
mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_maskDrawable);
if (mMaskDrawable != null) {
mMaskDrawable.setCallback(this);
}
mBorderDrawable = a.getDrawable(R.styleable.BezelImageView_borderDrawable);
if (mBorderDrawable != null) {
mBorderDrawable.setCallback(this);
}
mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress,
mDesaturateOnPress);
a.recycle();
// Other initialization.
mBlackPaint = new Paint();
mBlackPaint.setColor(0xff000000);
mMaskedPaint = new Paint();
mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
// Always want a cache allocated.
mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
if (mDesaturateOnPress) {
// Create a desaturate color filter for pressed state.
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
}
}
示例15: drawBackground
import android.graphics.Paint; //导入方法依赖的package包/类
public void drawBackground(Canvas canvas, Paint paint) {
canvas.save();
canvas.translate(getOffsetX(), getOffsetY());
paint.reset();
if(Utilities.isAllowFolderTransparentPrefEnabled(Launcher.getLauncherActivity().getApplicationContext())){
paint.setStyle(Paint.Style.STROKE);
}else {
paint.setStyle(Paint.Style.FILL);
}
paint.setXfermode(null);
paint.setAntiAlias(true);
int alpha = (int) Math.min(MAX_BG_OPACITY, BG_OPACITY * mColorMultiplier);
if(Utilities.getFolderPreviewBackgroundPrefEnabled(Launcher.getLauncherActivity().getApplicationContext()) != -1){
paint.setColor(Utilities.getFolderPreviewBackgroundPrefEnabled(Launcher.getLauncherActivity().getApplicationContext()));
}else {
paint.setColor(Color.argb(alpha, BG_INTENSITY, BG_INTENSITY, BG_INTENSITY));
}
float radius = getScaledRadius();
canvas.drawCircle(radius, radius, radius, paint);
canvas.clipPath(mClipPath, Region.Op.DIFFERENCE);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.TRANSPARENT);
paint.setShadowLayer(mStrokeWidth, 0, mStrokeWidth, Color.argb(SHADOW_OPACITY, 0, 0, 0));
canvas.drawCircle(radius, radius, radius, paint);
canvas.restore();
}