List of usage examples for android.graphics PorterDuffXfermode PorterDuffXfermode
public PorterDuffXfermode(PorterDuff.Mode mode)
From source file:Main.java
public static Bitmap getBitmap(Bitmap background, Bitmap contour, float alpha) { Paint paint = new Paint(); paint.setAntiAlias(true);//w ww . j av a 2s . com paint.setColor(Color.WHITE); paint.setDither(false); Bitmap bitmap = Bitmap.createBitmap(contour.getWidth(), contour.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Matrix m = new Matrix(); m.setScale(contour.getWidth() * 1.0f / background.getWidth(), contour.getHeight() * 1.0f / background.getHeight()); paint.setAlpha((int) (alpha * 0xff)); canvas.drawBitmap(background, m, paint); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); paint.setAlpha(0xff); canvas.drawBitmap(contour, 0, 0, paint); return bitmap; }
From source file:Main.java
/** * clip source bitmap into a circle bitmap * * @param src the source bitmap//from w ww.j ava 2 s .c om * @param recycle whether recycle the source bitmap * @param config bitmap config * @return clipped circle bitmap */ public static Bitmap createCircleBitmap(Bitmap src, boolean recycle, Bitmap.Config config) { if (src == null) { return null; } if (config == null) { config = Bitmap.Config.ARGB_8888; } Bitmap out = Bitmap.createBitmap(src.getWidth(), src.getHeight(), config); final Rect rect = new Rect(0, 0, Math.min(src.getWidth(), src.getHeight()), Math.min(src.getWidth(), src.getHeight())); Paint paint = new Paint(); paint.setAntiAlias(true); Canvas canvas = new Canvas(out); canvas.drawARGB(0, 0, 0, 0); RectF rectF = new RectF(rect); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, rect, rect, paint); if (recycle) { src.recycle(); } return out; }
From source file:Main.java
public static Bitmap combineImages(Bitmap bgd, Bitmap fg) { Bitmap bmp;/*from w w w. ja va2s . c o m*/ int width = bgd.getWidth() > fg.getWidth() ? bgd.getWidth() : fg.getWidth(); int height = bgd.getHeight() > fg.getHeight() ? bgd.getHeight() : fg.getHeight(); bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888); Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_ATOP)); Canvas canvas = new Canvas(bmp); canvas.drawBitmap(bgd, 0, 0, null); canvas.drawBitmap(fg, 0, 0, paint); return bmp; }
From source file:Main.java
public static Bitmap roundCornerFromFile(String filePath, int pixels) { try {/*from w ww. java 2 s . co m*/ Bitmap bitmap = BitmapFactory.decodeFile(filePath); if (bitmap == null) return null; Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); 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); bitmap.recycle(); bitmap = null; return output; } catch (OutOfMemoryError e) { return null; } catch (Exception e) { return null; } }
From source file:Main.java
public static Bitmap drawTextToBitmap(Bitmap bitmap, String gText) { OutputStream outStream = null; Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = Bitmap.Config.ARGB_8888; }/*from ww w. jav a 2s . com*/ String dataPath = Environment.getExternalStorageDirectory().toString() + "/SignChat/Temp/temp" + "0" + pictureNum + ".jpg"; try { FileOutputStream out = new FileOutputStream(dataPath); // NEWLY ADDED CODE STARTS HERE [ Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setColor(Color.WHITE); // Text Color paint.setStrokeWidth(12); // Text Size paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text // Overlapping // Pattern // some more settings... canvas.drawBitmap(bitmap, 0, 0, paint); canvas.drawText("Testing...", 10, 10, paint); // NEWLY ADDED CODE ENDS HERE ] bitmap.compress(CompressFormat.JPEG, 90, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap3(Drawable imageDrawable, int radius) { Bitmap d = ((BitmapDrawable) imageDrawable).getBitmap(); BitmapShader shader = new BitmapShader(d, TileMode.CLAMP, TileMode.CLAMP); int size = Math.min(d.getWidth(), d.getHeight()); Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); RectF outerRect = new RectF(0, 0, size, size); // float cornerRadius = radius; Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setShader(shader);// w w w. ja v a 2 s.c om paint.setAntiAlias(true); paint.setColor(Color.RED); canvas.drawCircle(outerRect.centerX(), outerRect.centerY(), d.getWidth() / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); imageDrawable.setBounds(0, 0, size, size); Canvas canvas1 = new Canvas(output); RectF outerRect1 = new RectF(0, 0, size, size); Paint paint1 = new Paint(Paint.ANTI_ALIAS_FLAG); paint1.setShader(shader); paint1.setAntiAlias(true); paint1.setColor(Color.RED); canvas1.drawCircle(outerRect1.centerX(), outerRect1.centerY(), d.getWidth() / 2, paint); paint1.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); return output; }
From source file:Main.java
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) { Bitmap sbmp;//ww w .ja v a 2 s . co m 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 int color = 0xffa19774; final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 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(Mode.SRC_IN)); canvas.drawBitmap(sbmp, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap getRoundBitmap(Bitmap bmp, float roundDP) { // roundDP *= Constants.screen_density; Bitmap bmpOut = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888); Canvas c = new Canvas(bmpOut); final Paint p = new Paint(); final RectF rectF = new RectF(0, 0, bmp.getWidth(), bmp.getHeight()); p.setAntiAlias(true);//from ww w.j a v a 2 s . c o m c.drawARGB(0, 0, 0, 0); p.setColor(Color.BLACK); c.drawRoundRect(rectF, roundDP, roundDP, p); p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); c.drawBitmap(bmp, 0, 0, p); return bmpOut; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int maxHeight, int pixels) { maxHeight = (int) (getApplicationContext().getResources().getDisplayMetrics().density * maxHeight); float scale = bitmap.getHeight() * 1.0f / maxHeight; int newWidth = (int) (bitmap.getWidth() / scale); Bitmap output = Bitmap.createBitmap(newWidth, maxHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xffffffff; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final Rect dstRect = new Rect(0, 0, newWidth, maxHeight); final RectF rectF = new RectF(dstRect); paint.setAntiAlias(true);// w w w. j ava2 s .co m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, (float) pixels, (float) pixels, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, dstRect, paint); return output; }
From source file:Main.java
public static Bitmap getClip(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); Paint paint = new Paint(); Rect rect = new Rect(0, 0, width, height); paint.setAntiAlias(true);/*from www. ja va2 s . c o m*/ canvas.drawARGB(0, 0, 0, 0); canvas.drawCircle(width / 2, height / 2, width / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, null, rect, paint); return output; }