本文整理汇总了Java中android.graphics.Xfermode类的典型用法代码示例。如果您正苦于以下问题:Java Xfermode类的具体用法?Java Xfermode怎么用?Java Xfermode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Xfermode类属于android.graphics包,在下文中一共展示了Xfermode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDraw
import android.graphics.Xfermode; //导入依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
Drawable drawable = getDrawable();
if (drawable instanceof BitmapDrawable) {
RectF rectF = new RectF(drawable.getBounds());
int restoreCount = canvas.saveLayer(rectF, null, Canvas.ALL_SAVE_FLAG);
getImageMatrix().mapRect(rectF);
Paint paint = ((BitmapDrawable) drawable).getPaint();
paint.setAntiAlias(true);
paint.setColor(0xff000000);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawRoundRect(rectF, RADIUS, RADIUS, paint);
Xfermode restoreMode = paint.getXfermode();
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
super.onDraw(canvas);
// Restore paint and canvas
paint.setXfermode(restoreMode);
canvas.restoreToCount(restoreCount);
} else {
super.onDraw(canvas);
}
}
示例2: onDraw
import android.graphics.Xfermode; //导入依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//创建一个图层,在图层上演示图形混合后的效果
int sc = canvas.saveLayer(null, mPaint, ALL_SAVE_FLAG);
canvas.translate(mWidth / 2, mHeight / 2);
int radius = Math.min(mWidth, mHeight) / 6;
mPaint.setColor(0xFFFEC336);
canvas.drawCircle(0, 0, radius, mPaint);
Xfermode oldMode = mPaint.getXfermode();
if (mXfermode != null) {
mPaint.setXfermode(mXfermode);
}
int size = Math.min(mWidth, mHeight) / 4;
mPaint.setColor(0xFF5596FF);
canvas.drawRect(0, 0, size, size, mPaint);
mPaint.setXfermode(oldMode);
canvas.restoreToCount(sc);
}
示例3: getCircleBitmap
import android.graphics.Xfermode; //导入依赖的package包/类
public Bitmap getCircleBitmap(Bitmap bitmap, int n) {
Bitmap bitmap2 = Bitmap.createBitmap((int)bitmap.getWidth(), (int)bitmap.getHeight(), (Bitmap.Config)Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap2);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
paint.setDither(true);
paint.setFilterBitmap(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(-65536);
canvas.drawOval(rectF, paint);
paint.setColor(-16776961);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(4.0f);
paint.setXfermode((Xfermode)new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return bitmap2;
}
示例4: drawProgressCircle
import android.graphics.Xfermode; //导入依赖的package包/类
/**
* 画进度内环
*
* @param int template 温度
* */
private void drawProgressCircle(Canvas canvas) {
int sc = canvas.saveLayer(0, 0, width, height, null,
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.drawBitmap(CircleBg3, null, RectfCircle, circlPaint);
Xfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
Paint circlePaint2 = new Paint();
circlePaint2.setAntiAlias(true);
circlePaint2.setXfermode(xfermode);
canvas.drawArc(RectfCircle, startAngle + angle, 360 - angle, true, circlePaint2);
circlePaint2.setXfermode(null);
canvas.restoreToCount(sc);
}
示例5: MaskBitmap
import android.graphics.Xfermode; //导入依赖的package包/类
private Bitmap MaskBitmap(Bitmap bitmap, Bitmap mask, int size, Xfermode mode) {
if (null == bitmap || mask == null) {
return null;
}
//定义期望大小的bitmap
Bitmap dstBmp = Bitmap.createBitmap(size, size, Config.ARGB_8888);
//定义一个画布
Canvas canvas = new Canvas(dstBmp);
//创建一个取消锯齿画笔
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
//定义需要绘制的某图片上的那一部分矩形空间
Rect src = new Rect(0, 0, mask.getWidth(), mask.getHeight());
//定义需要将上面的矩形绘制成新的矩形大小
Rect dst = new Rect(0, 0, size, size);
//将蒙版图片绘制成imageview本身的大小,这样从大小才会和UE标注的一样大
canvas.drawBitmap(mask, src, dst, paint);
//设置两张图片的相交模式
//至于这个函数介绍参考网址:http://blog.csdn.net/wm111/article/details/7299294
paint.setXfermode(mode);
//将src修改为需要添加mask的bitmap大小,因为是要将此bitmap整个添加上蒙版
src.right = bitmap.getWidth();
src.bottom = bitmap.getHeight();
//在已经绘制的mask上叠加bitmap
canvas.drawBitmap(bitmap, src, dst, paint);
return dstBmp;
}
示例6: MaskBitmap
import android.graphics.Xfermode; //导入依赖的package包/类
private Bitmap MaskBitmap(Bitmap bitmap, Bitmap mask, int size, Xfermode mode) {
if (null == bitmap || mask == null) {
return null;
}
Bitmap dstBmp = Bitmap.createBitmap(size, size, Config.ARGB_8888);
Canvas canvas = new Canvas(dstBmp);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
Rect src = new Rect(0, 0, mask.getWidth(), mask.getHeight());
Rect dst = new Rect(0, 0, size, size);
canvas.drawBitmap(mask, src, dst, paint);
paint.setXfermode(mode);
src.right = bitmap.getWidth();
src.bottom = bitmap.getHeight();
canvas.drawBitmap(bitmap, src, dst, paint);
return dstBmp;
}
示例7: onDraw
import android.graphics.Xfermode; //导入依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
Drawable maiDrawable = getDrawable();
if (!isInEditMode() && maiDrawable instanceof BitmapDrawable) {
Paint paint = ((BitmapDrawable) maiDrawable).getPaint();
Rect bitmapBounds = maiDrawable.getBounds();
rect.set(bitmapBounds);
int saveCount = canvas.saveLayer(rect, null,
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);
getImageMatrix().mapRect(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
final int color = 0xffffffff;
paint.setColor(color);
canvas.drawPath(boundPath, paint);
Xfermode oldMode = paint.getXfermode();
paint.setXfermode(duffMode);
super.onDraw(canvas);
paint.setXfermode(oldMode);
canvas.restoreToCount(saveCount);
drawHover(canvas);
drawBorder(canvas);
} else {
super.onDraw(canvas);
}
}
示例8: onDraw
import android.graphics.Xfermode; //导入依赖的package包/类
protected void onDraw(Canvas paramCanvas) {
Drawable localDrawable = getDrawable();
if (localDrawable == null)
return;
try {
if (this.paint == null) {
Paint localPaint1 = new Paint();
this.paint = localPaint1;
this.paint.setFilterBitmap(false);
Paint localPaint2 = this.paint;
Xfermode localXfermode1 = MASK_XFERMODE;
@SuppressWarnings("unused")
Xfermode localXfermode2 = localPaint2.setXfermode(localXfermode1);
}
float f1 = getWidth();
float f2 = getHeight();
int i = paramCanvas.saveLayer(0.0F, 0.0F, f1, f2, null, 31);
int j = getWidth();
int k = getHeight();
localDrawable.setBounds(0, 0, j, k);
localDrawable.draw(paramCanvas);
if ((this.mask == null) || (this.mask.isRecycled())) {
Bitmap localBitmap1 = createMask();
this.mask = localBitmap1;
}
Bitmap localBitmap2 = this.mask;
Paint localPaint3;
localPaint3 = this.paint;
paramCanvas.drawBitmap(localBitmap2, 0.0F, 0.0F, localPaint3);
paramCanvas.restoreToCount(i);
return;
} catch (Exception localException) {
StringBuilder localStringBuilder = new StringBuilder()
.append("Attempting to draw with recycled bitmap. View ID = ");
System.out.println("localStringBuilder==" + localStringBuilder);
}
}
示例9: draw
import android.graphics.Xfermode; //导入依赖的package包/类
public void draw(XulDC dc, int x1, int y1, int w1, int h1, float x2, float y2, float w2, float h2, Paint p) {
dc.save();
Xfermode xfermode = p.setXfermode(_colorKeyXferMode);
if (_xulDrawable == null) {
_xulDrawable = XulDrawable.fromBitmap(_frameImage, "", "");
}
dc.drawBitmap(_xulDrawable, x1, y1, w1, h1, x2, y2, w2, h2, p);
p.setXfermode(xfermode);
dc.restore();
}
示例10: onDraw
import android.graphics.Xfermode; //导入依赖的package包/类
protected void onDraw(Canvas paramCanvas) {
Drawable localDrawable = getDrawable();
if (localDrawable == null)
return;
try {
if (this.paint == null) {
Paint localPaint1 = new Paint();
this.paint = localPaint1;
this.paint.setFilterBitmap(false);
Paint localPaint2 = this.paint;
Xfermode localXfermode1 = MASK_XFERMODE;
@SuppressWarnings("unused")
Xfermode localXfermode2 = localPaint2.setXfermode(localXfermode1);
}
float f1 = getWidth();
float f2 = getHeight();
int i = paramCanvas.saveLayer(0.0F, 0.0F, f1, f2, null, 31);
int j = getWidth();
int k = getHeight();
localDrawable.setBounds(0, 0, j, k);
localDrawable.draw(paramCanvas);
if ((this.mask == null) || (this.mask.isRecycled())) {
Bitmap localBitmap1 = createMask();
this.mask = localBitmap1;
}
Bitmap localBitmap2 = this.mask;
Paint localPaint3 = this.paint;
paramCanvas.drawBitmap(localBitmap2, 0.0F, 0.0F, localPaint3);
paramCanvas.restoreToCount(i);
return;
} catch (Exception localException) {
StringBuilder localStringBuilder = new StringBuilder()
.append("Attempting to draw with recycled bitmap. View ID = ");
System.out.println("localStringBuilder=="+localStringBuilder);
}
}
示例11: onDraw
import android.graphics.Xfermode; //导入依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
Drawable myDrawable = getDrawable();
if (myDrawable!=null && myDrawable instanceof BitmapDrawable && mCornerRadius > 0) {
Paint paint = ((BitmapDrawable) myDrawable).getPaint();
final int color = 0xff000000;
Rect bitmapBounds = myDrawable.getBounds();
final RectF rectF = new RectF(bitmapBounds);
int saveCount = canvas.saveLayer(rectF, null,
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);
getImageMatrix().mapRect(rectF);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, mCornerRadius, mCornerRadius, paint);
Xfermode oldMode = paint.getXfermode();
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
super.onDraw(canvas);
paint.setXfermode(oldMode);
canvas.restoreToCount(saveCount);
} else {
super.onDraw(canvas);
}
}
示例12: clearCanvas
import android.graphics.Xfermode; //导入依赖的package包/类
private void clearCanvas(Canvas canvas, Point p) {
// 将点下面的线清除(前提是父容器必须有设置背景)
Xfermode xfermode = mPaint.getXfermode();
int color = mPaint.getColor();
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
mPaint.setColor(Color.TRANSPARENT);
canvas.drawCircle(p.x, p.y, mRadius, mPaint);
mPaint.setXfermode(xfermode);
mPaint.setColor(color);
}
示例13: onDraw
import android.graphics.Xfermode; //导入依赖的package包/类
protected void onDraw(Canvas paramCanvas) {
Drawable localDrawable = getDrawable();
if (localDrawable == null)
return;
try {
if (this.paint == null) {
Paint localPaint1 = new Paint();
this.paint = localPaint1;
this.paint.setFilterBitmap(false);
Paint localPaint2 = this.paint;
Xfermode localXfermode1 = MASK_XFERMODE;
@SuppressWarnings("unused")
Xfermode localXfermode2 = localPaint2.setXfermode(localXfermode1);
}
float f1 = getWidth();
float f2 = getHeight();
int i = paramCanvas.saveLayer(0.0F, 0.0F, f1, f2, null, Canvas.ALL_SAVE_FLAG);
int j = getWidth();
int k = getHeight();
localDrawable.setBounds(0, 0, j, k);
localDrawable.draw(paramCanvas);
if ((this.mask == null) || (this.mask.isRecycled())) {
Bitmap localBitmap1 = createMask();
this.mask = localBitmap1;
}
Bitmap localBitmap2 = this.mask;
Paint localPaint3 = this.paint;
paramCanvas.drawBitmap(localBitmap2, 0.0F, 0.0F, localPaint3);
paramCanvas.restoreToCount(i);
return;
} catch (Exception localException) {
StringBuilder localStringBuilder = new StringBuilder()
.append("Attempting to draw with recycled bitmap. View ID = ");
System.out.println("localStringBuilder=="+localStringBuilder);
}
}
示例14: onDraw
import android.graphics.Xfermode; //导入依赖的package包/类
protected void onDraw(Canvas paramCanvas)
{
Drawable localDrawable = getDrawable();
if (localDrawable == null)
return;
try
{
if (this.paint == null)
{
Paint localPaint1 = new Paint();
this.paint = localPaint1;
this.paint.setFilterBitmap(false);
Paint localPaint2 = this.paint;
Xfermode localXfermode1 = MASK_XFERMODE;
@SuppressWarnings("unused")
Xfermode localXfermode2 = localPaint2.setXfermode(localXfermode1);
}
float f1 = getWidth();
float f2 = getHeight();
int i = paramCanvas.saveLayer(0.0F, 0.0F, f1, f2, null, 31);
int j = getWidth();
int k = getHeight();
localDrawable.setBounds(0, 0, j, k);
localDrawable.draw(paramCanvas);
if ((this.mask == null) || (this.mask.isRecycled()))
{
Bitmap localBitmap1 = createMask();
this.mask = localBitmap1;
}
Bitmap localBitmap2 = this.mask;
Paint localPaint3 = this.paint;
paramCanvas.drawBitmap(localBitmap2, 0.0F, 0.0F, localPaint3);
paramCanvas.restoreToCount(i);
return;
} catch (Exception localException)
{
StringBuilder localStringBuilder = new StringBuilder().append("Attempting to draw with recycled bitmap. View ID = ");
System.out.println("localStringBuilder==" + localStringBuilder);
}
}
示例15: draw
import android.graphics.Xfermode; //导入依赖的package包/类
@Override
public void draw(@NonNull Rect outRect, @NonNull Canvas canvas, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
if (bitmap == null) {
bitmap = Bitmap.createBitmap(frame.right - frame.left, frame.bottom - frame.top, Bitmap.Config.ARGB_8888);
bitmapCanvas = new Canvas(bitmap);
}
bitmapCanvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR);
bitmapCanvas.translate(-x, 0);
super.draw(outRect, bitmapCanvas, text, start, end, x, top, y, bottom, paint);
Xfermode oldXfermode = paint.getXfermode();
paint.setXfermode(this.xfermode);
srcGroup.draw(outRect, bitmapCanvas, text, start, end, x, top, y, bottom, paint);
paint.setXfermode(oldXfermode);
canvas.drawBitmap(bitmap, x, 0, null);
}