List of usage examples for android.graphics Paint setXfermode
public Xfermode setXfermode(Xfermode xfermode)
From source file:de.vanita5.twittnuker.util.SwipebackActivityUtils.java
/** * //from w w w . j ava2s.co m * May cause OutOfMemoryError * * @param activity * @param cacheQuality * @return Activity screenshot */ private static Bitmap getActivityScreenshotInternal(final Activity activity, final int cacheQuality) { if (activity == null) return null; final Window w = activity.getWindow(); final View view = w.getDecorView(); final int width = view.getWidth(), height = view.getHeight(); if (width <= 0 || height <= 0) return null; final Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444); final Rect frame = new Rect(); view.getWindowVisibleDisplayFrame(frame); // Remove window background behind status bar. final Canvas c = new Canvas(b); view.draw(c); final Paint paint = new Paint(); paint.setColor(Color.TRANSPARENT); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); c.drawRect(frame.left, 0, frame.right, frame.top, paint); return b; }
From source file:com.balieiro.facebook.FriendItem.java
/** * The credit of the image processing performed by this method belongs * to the author of this site://ww w . ja v a 2 s .co m * http://www.piwai.info/transparent-jpegs-done-right/ * There is an amazing explanation on how to perform this kind of * images transformations. */ private static Bitmap getRoundedBitmap(Bitmap source, int pictureMask) { BitmapFactory.Options options = new BitmapFactory.Options(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // Starting with Honeycomb, we can load the bitmap as mutable. options.inMutable = true; } // We could also use ARGB_4444, but not RGB_565 (we need an alpha layer). options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap bitmap; if (source.isMutable()) { bitmap = source; } else { bitmap = source.copy(Bitmap.Config.ARGB_8888, true); source.recycle(); } // The bitmap is opaque, we need to enable alpha compositing. bitmap.setHasAlpha(true); Canvas canvas = new Canvas(bitmap); Bitmap mask = BitmapFactory.decodeResource(MyFacebookApp.getContext().getResources(), pictureMask); Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); canvas.drawBitmap(mask, 0, 0, paint); // We do not need the mask bitmap anymore. mask.recycle(); return bitmap; }
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 w w w. j a 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; }
From source file:Main.java
/** * clip source bitmap into a circle bitmap * * @param src the source bitmap//from w w w . ja v a 2s .c o m * @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 getCircularBitmap(Bitmap srcBitmap) { // Calculate the circular bitmap width with border int squareBitmapWidth = Math.min(srcBitmap.getWidth(), srcBitmap.getHeight()); //int squareBitmapWidth = 300; // Initialize a new instance of Bitmap Bitmap dstBitmap = Bitmap.createBitmap(squareBitmapWidth, // Width squareBitmapWidth, // Height Bitmap.Config.ARGB_8888 // Config );/*from w w w .j a va2 s . c om*/ Canvas canvas = new Canvas(dstBitmap); // Initialize a new Paint instance Paint paint = new Paint(); paint.setAntiAlias(true); Rect rect = new Rect(0, 0, squareBitmapWidth, squareBitmapWidth); RectF rectF = new RectF(rect); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // Calculate the left and top of copied bitmap float left = (squareBitmapWidth - srcBitmap.getWidth()) / 2; float top = (squareBitmapWidth - srcBitmap.getHeight()) / 2; canvas.drawBitmap(srcBitmap, left, top, paint); srcBitmap.recycle(); return dstBitmap; }
From source file:Main.java
public static Bitmap setReflection(Bitmap bitmap, int distance, float ratio) { final int reflectionGap = distance; int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1);/* w w w.j av a 2s.c o m*/ Bitmap reflectionBitmap = Bitmap.createBitmap(bitmap, 0, height / 2, width, (int) (height * ratio), matrix, false); Bitmap withReflectionBitmap = Bitmap.createBitmap(width, (height + (int) (height * ratio) + reflectionGap), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(withReflectionBitmap); canvas.drawBitmap(bitmap, 0, 0, null); Paint defaultPaint = new Paint(); defaultPaint.setColor(Color.TRANSPARENT); canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint); canvas.drawBitmap(reflectionBitmap, 0, height + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, withReflectionBitmap.getHeight(), 0x70ffffff, 0x00ffffff, Shader.TileMode.MIRROR); paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); canvas.drawRect(0, height, width, withReflectionBitmap.getHeight(), paint); return withReflectionBitmap; }
From source file:Main.java
/** * Method to get a rounded rectange bitmap * @param bitmap//from www.j a v a 2 s .c o m * @param pixels * @return */ public static Bitmap getRoundedRectBitmap(Bitmap bitmap, int pixels) { Bitmap result = null; try { result = Bitmap.createBitmap(150, 150, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); int color = 0xff424242; Paint paint = new Paint(); Rect rect = new Rect(0, 0, 200, 200); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(75, 75, 75, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); } catch (NullPointerException e) { } catch (OutOfMemoryError o) { } return result; }
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 2s . c om 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 getRoundImage(Bitmap oriImg, boolean recycleOld) { Bitmap targetBitmap = null;//from www. j a v a 2 s . com if (oriImg != null && !oriImg.isRecycled()) { int size = Math.min(oriImg.getWidth(), oriImg.getHeight()); int targetWidth = size; int targetHeight = size; targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(targetBitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); canvas.drawARGB(0, 0, 0, 0); canvas.drawCircle(targetWidth / 2f, targetHeight / 2f, targetWidth / 2f, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(oriImg, new Rect(0, 0, size, size), new Rect(0, 0, targetWidth, targetHeight), paint); if (recycleOld) { oriImg.recycle(); } } return targetBitmap; }
From source file:Main.java
public static Bitmap roundCorner(Bitmap src, float round) { int width = src.getWidth(); int height = src.getHeight(); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); canvas.drawARGB(0, 0, 0, 0);/* www . ja v a2 s . c om*/ final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.BLACK); final Rect rect = new Rect(0, 0, width, height); final RectF rectF = new RectF(rect); canvas.drawRoundRect(rectF, round, round, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, rect, rect, paint); return result; }