Java Code Examples for android.graphics.Paint#setXfermode()
The following examples show how to use
android.graphics.Paint#setXfermode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RxImageTool.java From RxTools-master with Apache License 2.0 | 6 votes |
/** * 转为圆形图片 * * @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 = src.copy(src.getConfig(), true); Paint paint = new Paint(); Canvas canvas = new Canvas(ret); Rect rect = new Rect(0, 0, width, height); paint.setAntiAlias(true); paint.setColor(Color.TRANSPARENT); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawARGB(0, 0, 0, 0); canvas.drawCircle(width >> 1, height >> 1, radius, paint); canvas.drawBitmap(src, rect, rect, paint); if (recycle && !src.isRecycled()) src.recycle(); return ret; }
Example 2
Source File: PopupZoomer.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Sets the bitmap to be used for the zoomed view. */ public void setBitmap(Bitmap bitmap) { if (mZoomedBitmap != null) { mZoomedBitmap.recycle(); mZoomedBitmap = null; } mZoomedBitmap = bitmap; // Round the corners of the bitmap so it doesn't stick out around the overlay. Canvas canvas = new Canvas(mZoomedBitmap); Path path = new Path(); RectF canvasRect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight()); float overlayCornerRadius = getOverlayCornerRadius(getContext()); path.addRoundRect(canvasRect, overlayCornerRadius, overlayCornerRadius, Direction.CCW); canvas.clipPath(path, Op.XOR); Paint clearPaint = new Paint(); clearPaint.setXfermode(new PorterDuffXfermode(Mode.SRC)); clearPaint.setColor(Color.TRANSPARENT); canvas.drawPaint(clearPaint); }
Example 3
Source File: ShadowDrawable.java From ShadowDrawable with MIT License | 6 votes |
private ShadowDrawable(int shape, int[] bgColor, int shapeRadius, int shadowColor, int shadowRadius, int offsetX, int offsetY) { this.mShape = shape; this.mBgColor = bgColor; this.mShapeRadius = shapeRadius; this.mShadowRadius = shadowRadius; this.mOffsetX = offsetX; this.mOffsetY = offsetY; mShadowPaint = new Paint(); mShadowPaint.setColor(Color.TRANSPARENT); mShadowPaint.setAntiAlias(true); mShadowPaint.setShadowLayer(shadowRadius, offsetX, offsetY, shadowColor); mShadowPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP)); mBgPaint = new Paint(); mBgPaint.setAntiAlias(true); }
Example 4
Source File: SyncPlayFragment.java From Musync with MIT License | 6 votes |
public Bitmap addGradient(Bitmap originalBitmap){ int width = originalBitmap.getWidth(); int height = originalBitmap.getHeight(); Bitmap updatedBitmap = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(updatedBitmap); canvas.drawBitmap(originalBitmap,0,0,null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0,0,0,height,getResources().getColor(R.color.colorAccent),getResources().getColor(R.color.colorAccent1), Shader.TileMode.CLAMP); paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawRect(0,0,width,height,paint); return updatedBitmap; }
Example 5
Source File: ClipImageView.java From Tok-Android with GNU General Public License v3.0 | 6 votes |
public void drawRectangleOrCircle(Canvas canvas) { Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); Canvas temp = new Canvas(bitmap); Paint transparentPaint = new Paint(Paint.ANTI_ALIAS_FLAG); PorterDuffXfermode porterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR); transparentPaint.setColor(Color.TRANSPARENT); temp.drawRect(0, 0, temp.getWidth(), temp.getHeight(), mPaint); transparentPaint.setXfermode(porterDuffXfermode); if (mDrawCircleFlag) { float cx = mClipBorder.left + mClipBorder.width() / 2f; float cy = mClipBorder.top + mClipBorder.height() / 2f; float radius = mClipBorder.height() / 2f; temp.drawCircle(cx, cy, radius, transparentPaint); } else { RectF rectF = new RectF(mClipBorder.left, mClipBorder.top, mClipBorder.right, mClipBorder.bottom); temp.drawRoundRect(rectF, mRoundCorner, mRoundCorner, transparentPaint); } canvas.drawBitmap(bitmap, 0, 0, null); }
Example 6
Source File: BitmapUtil.java From SortedContactUI with Apache License 2.0 | 6 votes |
/** * 获取圆角图片 * * @param bitmap * @param pixels * @return */ public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) { 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); final 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(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
Example 7
Source File: DisplayUtils.java From weMessage with GNU Affero General Public License v3.0 | 5 votes |
public static Bitmap createCircleBitmap(Bitmap bitmap) { Bitmap output; if (bitmap.getWidth() > bitmap.getHeight()) { output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); } else { output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(output); float r; final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); if (bitmap.getWidth() > bitmap.getHeight()) { r = bitmap.getHeight() / 2; } else { r = bitmap.getWidth() / 2; } paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(r, r, r, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
Example 8
Source File: BoomView.java From FileManager with Apache License 2.0 | 5 votes |
private void initPaint() { mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setFilterBitmap(true); mPaint.setStyle(Paint.Style.FILL); //动态获取?attr/colorPrimary //在xml获取需要api>21以上 TypedValue typedValue = new TypedValue(); getContext().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); mPaint.setColor(typedValue.data); mBitmapPaint = new Paint(); mBitmapPaint.setAntiAlias(true); mBitmapPaint.setDither(true); mBitmapPaint.setFilterBitmap(true); //圆形背景色作为dest,火箭作为src,src的绘画范围不超过dest mBitmapPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP)); mMeteorPaint = new Paint(); mMeteorPaint.setAntiAlias(true); mMeteorPaint.setDither(true); mMeteorPaint.setColor(Color.WHITE); mMeteorPaint.setFilterBitmap(true); mMeteorPaint.setStrokeWidth(5); mMeteorPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP)); }
Example 9
Source File: HUDView.java From scrog with Apache License 2.0 | 5 votes |
protected void onDraw(Canvas canvas) { if (mClear == false) { mTextObjectManager.drawObjects(canvas); } else { Paint clearPaint = new Paint(); clearPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); canvas.drawRect(0, 0, mParams.width, mParams.height, clearPaint); } }
Example 10
Source File: OvalImageView.java From android-apps with MIT License | 5 votes |
public static Bitmap getOvalCroppedBitmap(Bitmap bitmap, int radius) { Bitmap finalBitmap; if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false); else finalBitmap = bitmap; Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(), finalBitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); Paint paint = new Paint(); final Rect rect = new Rect(0, 0, finalBitmap.getWidth(), finalBitmap.getHeight()); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.parseColor("#BAB399")); RectF oval = new RectF(0, 0, 130, 150); canvas.drawOval(oval, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(finalBitmap, rect, oval, paint); return output; }
Example 11
Source File: ProgressBarCircularIndeterminate.java From TLint with Apache License 2.0 | 5 votes |
/** * Draw second animation of view */ private void drawSecondAnimation(Canvas canvas) { if (arcO == limite) arcD += 6; if (arcD >= 290 || arcO > limite) { arcO += 6; arcD -= 6; } if (arcO > limite + 290) { limite = arcO; arcO = limite; arcD = 1; } rotateAngle += 4; canvas.rotate(rotateAngle, getWidth() / 2, getHeight() / 2); Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); Canvas temp = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(backgroundColor); // temp.drawARGB(0, 0, 0, 255); temp.drawArc(new RectF(0, 0, getWidth(), getHeight()), arcO, arcD, true, paint); Paint transparentPaint = new Paint(); transparentPaint.setAntiAlias(true); transparentPaint.setColor(getResources().getColor(android.R.color.transparent)); transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); temp.drawCircle(getWidth() / 2, getHeight() / 2, (getWidth() / 2) - dpToPx(4, getResources()), transparentPaint); canvas.drawBitmap(bitmap, 0, 0, new Paint()); }
Example 12
Source File: HexagonImageView.java From android-apps with MIT License | 5 votes |
public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) { Bitmap finalBitmap; if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false); else finalBitmap = bitmap; Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(), finalBitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); Paint paint = new Paint(); final Rect rect = new Rect(0, 0, finalBitmap.getWidth(), finalBitmap.getHeight()); Point point1_draw = new Point(75, 0); Point point2_draw = new Point(0, 50); Point point3_draw = new Point(0, 100); Point point4_draw = new Point(75, 150); Point point5_draw = new Point(150, 100); Point point6_draw = new Point(150, 50); Path path = new Path(); path.moveTo(point1_draw.x, point1_draw.y); path.lineTo(point2_draw.x, point2_draw.y); path.lineTo(point3_draw.x, point3_draw.y); path.lineTo(point4_draw.x, point4_draw.y); path.lineTo(point5_draw.x, point5_draw.y); path.lineTo(point6_draw.x, point6_draw.y); path.close(); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.parseColor("#BAB399")); canvas.drawPath(path, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(finalBitmap, rect, rect, paint); return output; }
Example 13
Source File: PaintUtil.java From DragScaleCircleView with Apache License 2.0 | 5 votes |
/** * creates the paint object for drawing the translucent overlay outside the crop window. * */ public static Paint newSurroundingAreaOverlayPaint() { final Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); paint.setAntiAlias(true); return paint; }
Example 14
Source File: BitmapUtil.java From AndroidStudyDemo with GNU General Public License v2.0 | 5 votes |
/** * 获得带倒影的图片方法 * * @param bitmap 源Bitmap * @return 带倒影的Bitmap */ public static Bitmap createReflectionBitmap(Bitmap bitmap) { final int reflectionGap = 4; int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1); Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(bitmap, 0, 0, null); Paint deafalutPaint = new Paint(); canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint); canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); // Set the Transfer mode to be porter duff and destination in paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); // Draw a rectangle using the paint with our linear gradient canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }
Example 15
Source File: RippleAnimation.java From RippleAnimation with Apache License 2.0 | 5 votes |
private RippleAnimation(Context context, float startX, float startY, int radius) { super(context); //获取activity的根视图,用来添加本View mRootView = (ViewGroup) getActivityFromContext(context).getWindow().getDecorView(); mStartX = startX; mStartY = startY; mStartRadius = radius; mPaint = new Paint(); mPaint.setAntiAlias(true); //设置为擦除模式 mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); updateMaxRadius(); initListener(); }
Example 16
Source File: ImageUtils.java From LLApp with Apache License 2.0 | 5 votes |
public static Bitmap getRoundedCornerBitmap(Bitmap var0, float var1) { Bitmap var2 = Bitmap.createBitmap(var0.getWidth(), var0.getHeight(), Bitmap.Config.ARGB_8888); Canvas var3 = new Canvas(var2); int var4 = -12434878; Paint var5 = new Paint(); Rect var6 = new Rect(0, 0, var0.getWidth(), var0.getHeight()); RectF var7 = new RectF(var6); var5.setAntiAlias(true); var3.drawARGB(0, 0, 0, 0); var5.setColor(-12434878); var3.drawRoundRect(var7, var1, var1, var5); var5.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); var3.drawBitmap(var0, var6, var6, var5); return var2; }
Example 17
Source File: BezelImageView.java From cnode-android with MIT License | 5 votes |
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); } }
Example 18
Source File: CornerImageView.java From CrawlerForReader with Apache License 2.0 | 5 votes |
private void init(AttributeSet attrs) { setLayerType(LAYER_TYPE_HARDWARE, null); if (attrs != null) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CornerImageView); mShapeMode = a.getInt(R.styleable.CornerImageView_shape, 0); mRadius = a.getDimension(R.styleable.CornerImageView_radius, 0); mStrokeWidth = a.getDimension(R.styleable.CornerImageView_stroke_width, 0); mStrokeColor = a.getColor(R.styleable.CornerImageView_stroke_color, mStrokeColor); a.recycle(); } mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setFilterBitmap(true); mPaint.setColor(Color.BLACK); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mStrokePaint.setFilterBitmap(true); mStrokePaint.setColor(Color.BLACK); mPathPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPathPaint.setFilterBitmap(true); mPathPaint.setColor(Color.BLACK); mPathPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); mPath = new Path(); }
Example 19
Source File: ColorizeFaceActivity.java From FaceT with Mozilla Public License 2.0 | 4 votes |
private void lipLayer() { Canvas drawCanvas = new Canvas(temp); Paint mPaint = new Paint(); mPaint.setXfermode(mXfermode); int rougeLayer = 0xEEFAFAFA; mPaint.setColor(rougeLayer); mPaint.setStyle(Paint.Style.FILL); mPaint.setStrokeJoin(Paint.Join.ROUND); // set the join to round you want mPaint.setStrokeCap(Paint.Cap.ROUND); // set the paint cap to round too mPaint.setPathEffect(new CornerPathEffect(50)); mPaint.setStrokeWidth(1f); int sc = drawCanvas.saveLayer(0, 0, temp.getWidth(), temp.getHeight(), null, Canvas.ALL_SAVE_FLAG); mPaint.setMaskFilter(new BlurMaskFilter(60f, BlurMaskFilter.Blur.OUTER)); Path path = new Path(); path.reset(); path.moveTo(landmark_pt_x.get(48), landmark_pt_y.get(48)); for (int i = 49; i < 55; i++) path.lineTo(landmark_pt_x.get(i), landmark_pt_y.get(i) + 2f); path.lineTo(landmark_pt_x.get(64), landmark_pt_y.get(64) - 2f); path.lineTo(landmark_pt_x.get(63), landmark_pt_y.get(63) - 2f); path.lineTo(landmark_pt_x.get(62), landmark_pt_y.get(62) - 2f); path.lineTo(landmark_pt_x.get(60), landmark_pt_y.get(60) - 2f); path.lineTo(landmark_pt_x.get(48), landmark_pt_y.get(48) - 2f); path.close(); drawCanvas.drawPath(path, mPaint); path.reset(); path.moveTo(landmark_pt_x.get(48), landmark_pt_y.get(48)); path.lineTo(landmark_pt_x.get(59), landmark_pt_y.get(59) + 2f); path.lineTo(landmark_pt_x.get(58), landmark_pt_y.get(58) + 2f); path.lineTo(landmark_pt_x.get(57), landmark_pt_y.get(57) + 2f); path.lineTo(landmark_pt_x.get(56), landmark_pt_y.get(56) + 2f); path.lineTo(landmark_pt_x.get(55), landmark_pt_y.get(55) + 2f); path.lineTo(landmark_pt_x.get(54), landmark_pt_y.get(54) + 2f); for (int i = 64; i < 68; i++) path.lineTo(landmark_pt_x.get(i), landmark_pt_y.get(i) - 2f); path.lineTo(landmark_pt_x.get(60), landmark_pt_y.get(60) - 2f); path.lineTo(landmark_pt_x.get(48), landmark_pt_y.get(48) - 2f); path.close(); drawCanvas.drawPath(path, mPaint); }
Example 20
Source File: MjpegView.java From CameraV with GNU General Public License v3.0 | 4 votes |
public void run() { start = System.currentTimeMillis(); PorterDuffXfermode mode = new PorterDuffXfermode(PorterDuff.Mode.DST_OVER); Bitmap bm; int width; int height; Rect destRect; Canvas c = null; Paint p = new Paint(); while (mRun) { if(surfaceDone) { try { c = mSurfaceHolder.lockCanvas(); if (c == null) break; synchronized (mSurfaceHolder) { try { bm = mIn.readMjpegFrame(); if (bm == null) { mRun = false; break; } destRect = destRect(bm.getWidth(),bm.getHeight()); c.drawColor(Color.BLACK); c.drawBitmap(bm, null, destRect, p); if(showFps) { p.setXfermode(mode); if(ovl != null) { height = ((ovlPos & 1) == 1) ? destRect.top : destRect.bottom-ovl.getHeight(); width = ((ovlPos & 8) == 8) ? destRect.left : destRect.right -ovl.getWidth(); c.drawBitmap(ovl, width, height, null); } p.setXfermode(null); frameCounter++; } if (frameDelay > 0) Thread.sleep(frameDelay); } catch (Exception e) { Log.e(TAG, "catch IOException hit in run", e); } } } finally { if (c != null) { mSurfaceHolder.unlockCanvasAndPost(c); } } } } }