本文整理匯總了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);
}