@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); } }
@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); }
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; }
/** * 画进度内环 * * @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); }
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; }
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; }
@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); } }
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); } }
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(); }
public void draw(Canvas canvas, int x1, int y1, int w1, int h1, float x2, float y2, float w2, float h2, Paint p) { if (!_isCurrentFrameDecoded) { decodeFrame(); } canvas.save(); Xfermode xfermode = p.setXfermode(_colorKeyXferMode); XulDC.drawBitmap(canvas, _frameImage, x1, y1, w1, h1, x2, y2, w2, h2, p); p.setXfermode(xfermode); canvas.restore(); }
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); } }
@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); } }
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); }
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); } }
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); } }
@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); }
@SuppressWarnings("unused") public static void setXfermode(ImageView icon, Xfermode mode) { try { // Try to load/ cache the xfermode method. if (null == xfremode) { xfremode = ImageView.class.getDeclaredMethod("setXfermode", Xfermode.class); if (null != xfremode) xfremode.setAccessible(true); } if (null != xfremode) xfremode.invoke(icon, mode); } catch (Throwable t) { LogUtils.LOGE("ColorHelper", "Error with ImageView#setXfermode", t); } }
@Override public void setBleningMode(Xfermode mode) { super.setBleningMode(mode); if (paints != null) { for (PXPaint p : paints) { p.setBleningMode(mode); } } }
@SuppressLint("NewApi") private void init(AttributeSet attrs) { if (Build.VERSION.SDK_INT >= 11) { setLayerType( LAYER_TYPE_SOFTWARE, null ); } borderColor = DEFAULT_BORDER_COLOR; if(attrs != null){ TypedArray array = context.obtainStyledAttributes(attrs, R.styleable._RoundedImageView); if(array != null){ borderColor = array.getColor(R.styleable._RoundedImageView_borderColor, DEFAULT_BORDER_COLOR); borderWidth = array.getDimensionPixelSize(R.styleable._RoundedImageView_borderWidth, -1); roundWidth = array.getDimensionPixelSize(R.styleable._RoundedImageView_roundWidth, -1); array.recycle(); } } DisplayMetrics displayMetrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) getContext().getSystemService( Context.WINDOW_SERVICE ); windowManager.getDefaultDisplay().getMetrics( displayMetrics ); paint = new Paint(); paint.setStyle( Style.STROKE ); paint.setColor( borderColor ); paint.setAntiAlias( true ); paint.setStrokeWidth( borderWidth ); Xfermode xfermode = new PorterDuffXfermode( PorterDuff.Mode.SRC ); paint.setXfermode( xfermode ); drawRect = new RectF(); drawPath = new Path(); }
public void drawImage(BufferedImageWrap image, String tmp, float x, float y){ //System.err.println("drawImage: " + image.getBitmap().getWidth() + " : "+ image.getBitmap().getHeight()); Xfermode mode = paint.getXfermode(); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_OVER)); //canvas.drawBitmap(image.getBitmap(), x, y, paint); Bitmap bitmap = image.getBitmap(); bitmap.prepareToDraw(); canvas.drawBitmap(bitmap, canvas.getClipBounds(), canvas.getClipBounds(), paint); paint.setXfermode(mode); }
public void setXferMode(Xfermode xferMode) { mXfermode = xferMode; invalidate(); }
private Xfermode convertComposite(Canvas.Composite composite) { return xfermodes[composite.ordinal()]; }
public void setBleningMode(Xfermode mode) { blendingMode = mode; }
public Xfermode getBleningMode() { return blendingMode; }
/** * Set erase to true when the erase button is clicked. * * @param isErase {@code true} if erase is clicked {@code false} otherwise */ public void setErase(boolean isErase) { Xfermode xfermode = isErase ? new PorterDuffXfermode( PorterDuff.Mode.CLEAR) : null; drawPaint.setXfermode(xfermode); }
/** * Sets the blend mode to use when applying this fill */ void setBleningMode(Xfermode mode);
/** * Returns the blend mode to use when applying this fill. * * @return {@link Xfermode} May be <code>null</code> */ Xfermode getBleningMode();