public void setEraseMode(boolean erase) { if (erase) { mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); } else { mPaint.setXfermode(null); } }
private Bitmap mask(Bitmap image, Bitmap mask) { // todo: image wiederholen und skalierung richtig Bitmap bitmapOut = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmapOut); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); if (tileImage) { BitmapDrawable background = new BitmapDrawable(image); // in this case, you want to tile the entire view background.setBounds(0, 0, mask.getWidth(), mask.getHeight()); background.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); background.draw(canvas); } else { canvas.drawBitmap(image, (int) (mask.getWidth() * 0.5 - image.getWidth() * 0.5), 0, paint); } Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG); xferPaint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawBitmap(mask, 0, 0, xferPaint); xferPaint.setXfermode(null); return bitmapOut; }
@Override public boolean onOptionsItemSelected(MenuItem item) { mPaint.setXfermode(null); mPaint.setAlpha(0xFF); switch (item.getItemId()) { case COLOR_MENU_ID: new ColorPickerDialog(this, this, mPaint.getColor()).show(); return true; case EMBOSS_MENU_ID: if (mPaint.getMaskFilter() != mEmboss) { mPaint.setMaskFilter(mEmboss); } else { mPaint.setMaskFilter(null); } return true; case BLUR_MENU_ID: if (mPaint.getMaskFilter() != mBlur) { mPaint.setMaskFilter(mBlur); } else { mPaint.setMaskFilter(null); } return true; case ERASE_MENU_ID: mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); return true; case SRCATOP_MENU_ID: mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP)); mPaint.setAlpha(0x80); return true; } return super.onOptionsItemSelected(item); }
public CircleBatteryMeterDrawable(Resources res) { super(); mDisposed = false; mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setColor(res.getColor(R.color.status_bar_clock_color)); Typeface font = Typeface.create("sans-serif-condensed", Typeface.NORMAL); mTextPaint.setTypeface(font); mTextPaint.setTextAlign(Paint.Align.CENTER); mFrontPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mFrontPaint.setStrokeCap(Paint.Cap.BUTT); mFrontPaint.setDither(true); mFrontPaint.setStrokeWidth(0); mFrontPaint.setStyle(Paint.Style.STROKE); mFrontPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP)); mBackPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBackPaint.setColor(res.getColor(R.color.batterymeter_frame_color)); mBackPaint.setStrokeCap(Paint.Cap.BUTT); mBackPaint.setDither(true); mBackPaint.setStrokeWidth(0); mBackPaint.setStyle(Paint.Style.STROKE); mBackPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR)); mBoltPaint = new Paint(); mBoltPaint.setAntiAlias(true); mBoltPaint.setColor(getColorForLevel(50)); mBoltPoints = loadBoltPoints(res); }
private void undo() { try { if (undoPathList.size() > 0) { HistoryItem item = undoPathList.get(undoPathList.size() - 1); redoPathList.add(item); undoPathList.remove(undoPathList.size() - 1); Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR)); mCacheCanvas.drawPaint(paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC)); for (int i = 0; i < undoPathList.size(); i++) { HistoryItem item_t = undoPathList.get(i); if (item_t.getType() == HistoryItem.TYPE_PATH) { mCacheCanvas.drawPath(item_t.getPath(), item_t.getPaint()); } else if (item_t.getType() == HistoryItem.TYPE_TEXT) { mCacheCanvas.drawText( item_t.getText(), item_t.getTextStartPoint().x, item_t.getTextStartPoint().y, item_t.getPaint()); } else if (item_t.getType() == HistoryItem.TYPE_ERASER) { item_t.getPaint().setXfermode(new PorterDuffXfermode(Mode.DST_IN)); mCacheCanvas.drawPath(item_t.getPath(), item_t.getPaint()); } } handler.sendEmptyMessage(CustomDrawViewCH_INVALIDATE); } } catch (Exception e) { e.printStackTrace(); } }
public Bitmap getCircleBitmap(Bitmap paramBitmap, int paramInt) { if (paramBitmap == null) { paramBitmap = null; return paramBitmap; } if (paramInt == 0) paramInt = Math.min(paramBitmap.getWidth(), paramBitmap.getHeight()); while (true) { Bitmap localBitmap = Bitmap.createBitmap(paramInt, paramInt, Bitmap.Config.ARGB_8888); Canvas localCanvas = new Canvas(localBitmap); Paint localPaint = new Paint(); Rect localRect = new Rect( this.mStrokeWidth, this.mStrokeWidth, paramInt - this.mStrokeWidth, paramInt - this.mStrokeWidth); RectF localRectF = new RectF(localRect); localPaint.setAntiAlias(true); localCanvas.drawArc(localRectF, 0.0F, 360.0F, true, localPaint); localPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); localCanvas.drawBitmap(paramBitmap, localRect, localRect, localPaint); paramBitmap = localBitmap; if (this.mStrokeWidth <= 0) break; paramBitmap = new RectF(new Rect(0, 0, paramInt, paramInt)); localPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER)); localPaint.setColor(this.mStrokeColor); localCanvas.drawArc(paramBitmap, 0.0F, 360.0F, false, localPaint); return localBitmap; } }
public void run() { start = System.currentTimeMillis(); PorterDuffXfermode mode = new PorterDuffXfermode(PorterDuff.Mode.DST_OVER); int width; int height; Paint p = new Paint(); Bitmap ovl = null; while (mRun) { Rect destRect = null; Canvas c = null; if (surfaceDone) { try { if (bmp == null) { bmp = Bitmap.createBitmap(imgWidth, imgHeight, Bitmap.Config.ARGB_8888); } mIn.readMjpegFrame(bmp); destRect = destRect(bmp.getWidth(), bmp.getHeight()); c = mSurfaceHolder.lockCanvas(); synchronized (mSurfaceHolder) { c.drawBitmap(bmp, null, destRect, p); if (showFps) { p.setXfermode(mode); if (ovl != null) { // false indentation to fix forum layout 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 ((System.currentTimeMillis() - start) >= 1000) { fps = String.valueOf(frameCounter) + "fps"; frameCounter = 0; start = System.currentTimeMillis(); if (ovl != null) ovl.recycle(); ovl = makeFpsOverlay(overlayPaint); } } } } catch (IOException e) { System.out.println(e.toString()); } catch (Exception e) { System.out.println(e.toString()); } finally { if (c != null) mSurfaceHolder.unlockCanvasAndPost(c); } } } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Drawable mDrawable = getDrawable(); if (mDrawable == null) { return; } if (mDrawable.getIntrinsicWidth() == 0 || mDrawable.getIntrinsicHeight() == 0) { return; // nothing to draw (empty bounds) } if (null == maskBitmap) { return; } int saveCount = canvas.getSaveCount(); canvas.save(); paint.setFilterBitmap(false); paint.setXfermode(mXfermode); canvas.drawBitmap(maskBitmap, null, mRoundRect, paint); paint.setXfermode(null); canvas.restoreToCount(saveCount); }
public static void init() { if (initialized) return; maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); addPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.LIGHTEN)); clearPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); hiLite.setColor(0x5000ff00); initialized = true; }
@Override public void onAnimDraw(SurfaceHolder holder) { while (!isDragEnd) { Canvas canvas = null; int size = 0; int oldsize = 0; while ((size = mStack.size()) > 0 && null != holder) { if (oldsize == size) { break; } oldsize = size; try { canvas = holder.lockCanvas(null); canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR); canvas.setDrawFilter(pdf); for (int i = 0; i < shadowBitmap.length; i++) { int[] _point = mStack.get((int) (size * (1 - (i + 1) * 0.1))); dst.set( _point[0] - headWidth / 2, _point[1] - headWidth / 2, _point[0] + headWidth / 2, _point[1] + headWidth / 2); canvas.drawBitmap(mDstB, null, dst, paint); paint.setXfermode(xfermode); canvas.drawBitmap(shadowBitmap[i], null, dst, paint); paint.setXfermode(null); } ballIconRect.set( _lastX - ballIcon.getIntrinsicWidth() / 2, _lastY - ballIcon.getIntrinsicHeight() / 2, _lastX + ballIcon.getIntrinsicWidth() / 2, _lastY + ballIcon.getIntrinsicHeight() / 2); ballIcon.setBounds(ballIconRect); ballIcon.draw(canvas); } catch (Exception e) { e.printStackTrace(); } finally { if (null != canvas) { holder.unlockCanvasAndPost(canvas); } else { break; } } } mStack.clear(); try { Thread.sleep(15); } catch (InterruptedException e) { e.printStackTrace(); } } }
public static void prepareResources() { sUploadBitmap = Bitmap.createBitmap(TILE_SIZE, TILE_SIZE, Config.ARGB_8888); sCanvas = new Canvas(sUploadBitmap); sBitmapPaint = new Paint(Paint.FILTER_BITMAP_FLAG); sBitmapPaint.setXfermode(new PorterDuffXfermode(Mode.SRC)); sPaint = new Paint(); sPaint.setXfermode(new PorterDuffXfermode(Mode.SRC)); sPaint.setColor(Color.TRANSPARENT); }
private void init(Context context, AttributeSet attrs) { paint = new Paint(); paint.setColor(Color.WHITE); paint.setAntiAlias(true); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); paint2 = new Paint(); paint2.setXfermode(null); }
public void setErase(boolean isErase) { erase = isErase; if (erase) { drawPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); // this.setColor("#FFFFFFFF");//set the color to white } else { drawPaint.setXfermode(null); // this.setColor(paintColor); //if erase is set to false, it will use the previous color. } }
@SuppressLint("DrawAllocation") @Override protected void onDraw(Canvas canvas) { if (!isInEditMode()) { int i = canvas.saveLayer(0.0f, 0.0f, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG); try { Bitmap bitmap = mWeakBitmap != null ? mWeakBitmap.get() : null; // Bitmap not loaded. if (bitmap == null || bitmap.isRecycled()) { Drawable drawable = getDrawable(); if (drawable != null) { // Allocation onDraw but it's ok because it will not always be called. bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); Canvas bitmapCanvas = new Canvas(bitmap); drawable.setBounds(0, 0, getWidth(), getHeight()); drawable.draw(bitmapCanvas); // If mask is already set, skip and use cached mask. if (mMaskBitmap == null || mMaskBitmap.isRecycled()) { mMaskBitmap = getBitmap(); } // Draw Bitmap. mPaint.reset(); mPaint.setFilterBitmap(false); mPaint.setXfermode(sXfermode); // mBitmapShader = new BitmapShader(mMaskBitmap, // Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); // mPaint.setShader(mBitmapShader); bitmapCanvas.drawBitmap(mMaskBitmap, 0.0f, 0.0f, mPaint); mWeakBitmap = new WeakReference<Bitmap>(bitmap); } } // Bitmap already loaded. if (bitmap != null) { mPaint.setXfermode(null); // mPaint.setShader(null); canvas.drawBitmap(bitmap, 0.0f, 0.0f, mPaint); return; } } catch (Exception e) { System.gc(); LogUtil.e( TAG, String.format("Failed to draw, Id :: %s. Error occurred :: %s", getId(), e.toString())); } finally { canvas.restoreToCount(i); } } else { super.onDraw(canvas); } }
@Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.BLACK); canvas.drawBitmap(mSrcBitmap, 0, 0, null); canvas.drawBitmap(mRefBitmap, 0, mSrcBitmap.getHeight(), null); mPaint.setXfermode(mXfermode); // 绘制渐变效果矩形 canvas.drawRect( 0, mSrcBitmap.getHeight(), mRefBitmap.getWidth(), mSrcBitmap.getHeight() * 2, mPaint); mPaint.setXfermode(null); }
public void clearCanvas() { Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR)); if (mCacheCanvas != null && undoPathList != null && redoPathList != null) { mCacheCanvas.drawPaint(paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC)); handler.sendEmptyMessage(CustomDrawViewCH_INVALIDATE); undoPathList.clear(); redoPathList.clear(); } }
private void eraseArea(byte[] packetData) { try { int penWidthNum = myConvertByteArrToInt_bigend(packetData, 4); int penColorNum = myConvertByteArrToInt_bigend(packetData, 8); int eraserWidth = myConvertByteArrToInt_bigend(packetData, 12); int eraserHeight = myConvertByteArrToInt_bigend(packetData, 16); int nums = myConvertByteArrToInt_bigend(packetData, 20); int BYTES_PER_COORDINATE = 2; for (int i = 0; i < nums / 4; i++) { int x = xCoordinateMap( myConvertByteArrToShort_bigend(packetData, 24 + i * 2 * BYTES_PER_COORDINATE)); int y = yCoordinateMap( myConvertByteArrToShort_bigend( packetData, 24 + i * 2 * BYTES_PER_COORDINATE + BYTES_PER_COORDINATE)); int x1, y1, x2, y2; x1 = x - (eraserWidth / 2 + penWidthNum); y1 = y - (eraserHeight / 2 + penWidthNum); x2 = x + (eraserWidth / 2 + penWidthNum); y2 = y + (eraserHeight / 2 + penWidthNum); if (i == 0) { mPath = new Path(); mPath.addRect(x1, y1, x2, y2, Direction.CW); mPaint = getAPaint(); mPaint.setStrokeWidth(penWidthMap.get(penWidthNum)); mPaint.setColor(penColorMap.get(penColorNum)); mPaint.setStyle(Style.FILL_AND_STROKE); mPaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR)); HistoryItem item = new HistoryItem(HistoryItem.TYPE_PATH, mPaint, mPath, null, null); undoPathList.add(item); // mCacheCanvas.drawPath(mPath, mPaint); } else { mPath.addRect(x1, y1, x2, y2, Direction.CW); mPaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR)); mCacheCanvas.drawPath(mPath, mPaint); } handler.sendEmptyMessage(CustomDrawViewCH_INVALIDATE); if (!((ClassWorkActivity) mContext).isScreenLocked()) { break; } } // end of for } catch (Exception e) { e.printStackTrace(); Logg.e(TAG, "erase error"); } }
public void drawWithoutTransform(Canvas canvas) { if (mode != null) { textPaint.setXfermode(mode.xfermode); borderPaint.setXfermode(mode.xfermode); } if (stroke != null) { canvas.drawTextOnPath(text, stroke.getPath(), 0.0F, 0.0F, textPaint); if (hasBorder) { canvas.drawTextOnPath(text, stroke.getPath(), 0.0F, 0.0F, borderPaint); } } }
public void setEraseMode(Boolean toggle) { eraseState = toggle; if (eraseState) { Log.d(LCAT, "Setting Erase Mode to True."); tiPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); } else { Log.d(LCAT, "Setting Erase Mode to False."); tiPaint.setXfermode(null); } tiPaint.setAlpha(alphaState); }
@Override protected void onDraw(Canvas canvas) { // if (y > -50) { // y--; // } // 采用三阶贝塞尔 不停地改变X 模拟水波效果 if (x > 50) { isLeft = true; } else if (x < 0) { isLeft = false; } if (isLeft) { x = x - 1; } else { x = x + 1; } mPath.reset(); y = (int) ((1 - mPercent / 100f) * mHeight); // 设置起点 mPath.moveTo(0, y); // 画二阶贝塞尔曲线,前两个为辅助坐标点 第三个点为终点 mPath.cubicTo(100 + x * 2, 50 + y, 100 + x * 2, y - 50, mWidth, y); mPath.lineTo(mWidth, mHeight); // 充满整个画布 mPath.lineTo(0, mHeight); // 充满整个画布 mPath.close(); // 清除掉图像 不然path会重叠 mBitmap.eraseColor(Color.parseColor("#00000000")); // dst // mCanvas.drawBitmap(bgBitmap,0,0,null); // mSRCPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); mCanvas.drawCircle(mWidth / 2, mHeight / 2, mWidth / 2, mSRCPaint); mWavePaint.setXfermode(mMode); // src mCanvas.drawPath(mPath, mWavePaint); mWavePaint.setXfermode(null); // 清空mBitmap,不然path会重叠 canvas.drawBitmap(mBitmap, 0, 0, null); String str = mPercent + ""; mTextPaint.setTextSize(80); float txtLength = mTextPaint.measureText(str); canvas.drawText(str, mWidth / 2 - txtLength / 2, mHeight / 2 + 15, mTextPaint); mTextPaint.setTextSize(40); canvas.drawText("%", mWidth / 2 + 50, mHeight / 2 - 20, mTextPaint); postInvalidateDelayed(10); }
/** * 将图片转化为圆形头像 @Title: toRoundBitmap * * @throws */ public static Bitmap toRoundBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float roundPx; float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom; if (width <= height) { roundPx = width / 2; left = 0; top = 0; right = width; bottom = width; height = width; dst_left = 0; dst_top = 0; dst_right = width; dst_bottom = width; } else { roundPx = height / 2; float clip = (width - height) / 2; left = clip; right = width - clip; top = 0; bottom = height; width = height; dst_left = 0; dst_top = 0; dst_right = height; dst_bottom = height; } Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom); final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom); final RectF rectF = new RectF(dst); paint.setAntiAlias(true); // 设置画笔无锯齿 canvas.drawARGB(0, 0, 0, 0); // 填充整个Canvas // 以下有两种方法画圆,drawRounRect和drawCircle canvas.drawRoundRect( rectF, roundPx, roundPx, paint); // 画圆角矩形,第一个参数为图形显示区域,第二个参数和第三个参数分别是水平圆角半径和垂直圆角半径。 // canvas.drawCircle(roundPx, roundPx, roundPx, paint); paint.setXfermode( new PorterDuffXfermode( Mode.SRC_IN)); // 设置两张图片相交时的模式,参考http://trylovecatch.iteye.com/blog/1189452 canvas.drawBitmap(bitmap, src, dst, paint); // 以Mode.SRC_IN模式合并bitmap和已经draw了的Circle return output; }
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(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final 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")); canvas.drawCircle( finalBitmap.getWidth() / 2 + 0.7f, finalBitmap.getHeight() / 2 + 0.7f, finalBitmap.getWidth() / 2 + 0.1f, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(finalBitmap, rect, rect, paint); return output; }
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); } }
/** * @param bmp * @param radius * @return */ public static Bitmap getCroppedBitmap(Bitmap bmp, float radius) { Bitmap sbmp; int width = (int) radius; if (bmp.getWidth() != width || bmp.getHeight() != width) { sbmp = Bitmap.createScaledBitmap(bmp, width, width, false); } else { sbmp = bmp; } Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight()); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.parseColor("#BAB399")); canvas.drawCircle( sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f, sbmp.getWidth() / 2 + 0.1f, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(sbmp, rect, rect, paint); return output; }
/** 设置Xfermode模式为DST_OUT,并绘制扫的路径 */ private void drawPath() { // TODO Auto-generated method stub mOutterPaint.setXfermode(new PorterDuffXfermode(Mode.DST_OUT)); mCanvas.drawPath(mPath, mOutterPaint); }
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) { Bitmap sbmp; if (bmp.getWidth() != radius || bmp.getHeight() != radius) sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false); else sbmp = bmp; Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight()); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); canvas.drawARGB(0, 255, 255, 255); paint.setColor(Color.parseColor("#7f97d2")); canvas.drawCircle( sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f, sbmp.getWidth() / 2 - strokeWidth, paint); // 2-9f paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(sbmp, rect, rect, paint); // Paint pTouch = new Paint(Paint.ANTI_ALIAS_FLAG); // pTouch.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); // pTouch.setAlpha(255); // pTouch.setColor(Color.TRANSPARENT); // pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL)); // canvas.drawCircle(sbmp.getWidth() / 2-.6f, sbmp.getHeight() / 2, ((float) // Math.ceil((sbmp.getHeight()+15)/11))+.2f, pTouch); // canvas.drawCircle(sbmp.getWidth() / 2-.6f, sbmp.getHeight() / 2, 57, pTouch); return output; }
public Cling(Context context) { this(context, null, 0); // bmp = Bitmap.createBitmap(Utils3D.getScreenWidth(), Utils3D.getScreenHeight(), // Bitmap.Config.ARGB_8888); // canvas = new Canvas(bmp); grad = new GradientDrawable( // 渐变色 Orientation.TOP_BOTTOM, new int[] {Color.BLACK, Color.WHITE}); options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.RGB_565; src1 = new Rect(); dst1 = new Rect(); src2 = new Rect(); dst2 = new Rect(); mErasePaint = new Paint(); mErasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); // mErasePaint.setColor(0xFF18b7de); mErasePaint.setAlpha(0); mErasePaint.setAntiAlias(true); mErasePaint.setStyle(Paint.Style.FILL); mErasePaint.setStrokeWidth(4); normalPaint = new Paint(); normalPaint.setAntiAlias(true); normalPaint.setStyle(Paint.Style.STROKE); normalPaint.setStrokeWidth(strokeWidth); normalPaint.setColor(strokeColor); }
public NormalBatteryMeterDrawable(Resources res, boolean horizontal) { super(); mHorizontal = horizontal; mDisposed = false; mFramePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mFramePaint.setColor(res.getColor(R.color.batterymeter_frame_color)); mFramePaint.setDither(true); mFramePaint.setStrokeWidth(0); mFramePaint.setStyle(Paint.Style.FILL_AND_STROKE); mFramePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP)); mBatteryPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBatteryPaint.setDither(true); mBatteryPaint.setStrokeWidth(0); mBatteryPaint.setStyle(Paint.Style.FILL_AND_STROKE); mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setColor(res.getColor(R.color.batterymeter_bolt_color)); Typeface font = Typeface.create("sans-serif-condensed", Typeface.BOLD); mTextPaint.setTypeface(font); mTextPaint.setTextAlign(Paint.Align.CENTER); mWarningTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mWarningTextPaint.setColor(mColors[1]); font = Typeface.create("sans-serif", Typeface.BOLD); mWarningTextPaint.setTypeface(font); mWarningTextPaint.setTextAlign(Paint.Align.CENTER); mBoltPaint = new Paint(); mBoltPaint.setAntiAlias(true); mBoltPaint.setColor(res.getColor(R.color.batterymeter_bolt_color)); mBoltPoints = loadBoltPoints(res); }
public void init(AttributeSet attrs) { TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.SlantedTextView); mTextSize = array.getDimension(R.styleable.SlantedTextView_slantedTextSize, mTextSize); mTextColor = array.getColor(R.styleable.SlantedTextView_slantedTextColor, mTextColor); mSlantedLength = array.getDimension(R.styleable.SlantedTextView_slantedLength, mSlantedLength); mSlantedBackgroundColor = array.getColor(R.styleable.SlantedTextView_slantedBackgroundColor, mSlantedBackgroundColor); if (array.hasValue(R.styleable.SlantedTextView_slantedText)) { mSlantedText = array.getString(R.styleable.SlantedTextView_slantedText); } if (array.hasValue(R.styleable.SlantedTextView_slantedMode)) { mMode = array.getInt(R.styleable.SlantedTextView_slantedMode, 0); } array.recycle(); mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); mPaint.setAntiAlias(true); mPaint.setColor(mSlantedBackgroundColor); mTextPaint = new TextPaint(); mTextPaint.setAntiAlias(true); mTextPaint.setTextSize(mTextSize); mTextPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.ADD)); mTextPaint.setColor(mTextColor); mTextPaint.setTextAlign(Paint.Align.CENTER); }
public static void getAvatarForFancyQrCode(GetAvatarListener getAvatarListener) { Paint paint = new Paint(); paint.setAntiAlias(true); Resources res = BitherApplication.mContext.getResources(); Bitmap shape = BitmapFactory.decodeResource(res, R.drawable.avatar_for_fancy_qr_code_shape); Bitmap result = Bitmap.createBitmap(shape.getWidth(), shape.getHeight(), shape.getConfig()); Canvas c = new Canvas(result); c.drawBitmap(shape, 0, 0, paint); Paint avatarPaint = new Paint(); avatarPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); avatarPaint.setAntiAlias(true); Bitmap avatarBit = getAvatarBit(); if (avatarBit == null) { if (getAvatarListener != null) { getAvatarListener.fileNoExist(); } return; } c.drawBitmap( avatarBit, null, new Rect(0, 0, result.getWidth(), result.getHeight()), avatarPaint); Bitmap overlay = BitmapFactory.decodeResource(res, R.drawable.avatar_for_fancy_qr_code_overlay); c.drawBitmap(overlay, null, new Rect(0, 0, result.getWidth(), result.getHeight()), paint); if (result != null) { if (getAvatarListener != null) { getAvatarListener.success(result); } } }