List of usage examples for android.graphics Paint setXfermode
public Xfermode setXfermode(Xfermode xfermode)
From source file:ua.com.spacetv.mycookbook.fragments.FragTextRecipe.java
/** * Rounding corners on bitmap//w ww .j a v a2 s .c o m * * @param bitmap image of recipe * @param pixels - radius * @return processed bitmap */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.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); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, pixels, pixels, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Context context, Bitmap input, int dips, int w, int h, boolean squareTL, boolean squareTR, boolean squareBL, boolean squareBR) { Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888); Canvas canvas = new Canvas(output); final float densityMultiplier = context.getResources().getDisplayMetrics().density; final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, w, h); final RectF rectF = new RectF(rect); //make sure that our rounded corner is scaled appropriately final float roundPx = dips * densityMultiplier; paint.setAntiAlias(true);/* w w w. j a va2 s .com*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); //draw rectangles over the corners we want to be square if (squareTL) { canvas.drawRect(0, 0, w / 2, h / 2, paint); } if (squareTR) { canvas.drawRect(w / 2, 0, w, h / 2, paint); } if (squareBL) { canvas.drawRect(0, h / 2, w / 2, h, paint); } if (squareBR) { canvas.drawRect(w / 2, h / 2, w, h, paint); } paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(input, 0, 0, paint); return output; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Context context, Bitmap input, int pixels, int w, int h, boolean squareTL, boolean squareTR, boolean squareBL, boolean squareBR) { Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final float densityMultiplier = context.getResources().getDisplayMetrics().density; final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, w, h); final RectF rectF = new RectF(rect); //make sure that our rounded corner is scaled appropriately final float roundPx = pixels * densityMultiplier; paint.setAntiAlias(true);//from www.j av a 2 s . c o m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); //draw rectangles over the corners we want to be square if (squareTL) { canvas.drawRect(0, 0, w / 2, h / 2, paint); } if (squareTR) { canvas.drawRect(w / 2, 0, w, h / 2, paint); } if (squareBL) { canvas.drawRect(0, h / 2, w / 2, h, paint); } if (squareBR) { canvas.drawRect(w / 2, h / 2, w, h, paint); } paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(input, 0, 0, paint); return output; }
From source file:de.mrapp.android.util.BitmapUtil.java
/** * Clips the corners of a bitmap in order to transform it into a round shape. Additionally, the * bitmap is resized to a specific size. Bitmaps, whose width and height are not equal, will be * clipped to a square beforehand./* w w w . jav a2 s . c om*/ * * @param bitmap * The bitmap, which should be clipped, as an instance of the class {@link Bitmap}. The * bitmap may not be null * @param size * The size, the bitmap should be resized to, as an {@link Integer} value in pixels. The * size must be at least 1 * @return The clipped bitmap as an instance of the class {@link Bitmap} */ public static Bitmap clipCircle(@NonNull final Bitmap bitmap, final int size) { Bitmap squareBitmap = clipSquare(bitmap, size); int squareSize = squareBitmap.getWidth(); float radius = (float) squareSize / 2.0f; Bitmap clippedBitmap = Bitmap.createBitmap(squareSize, squareSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(clippedBitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.BLACK); canvas.drawCircle(radius, radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(squareBitmap, new Rect(0, 0, squareSize, squareSize), new Rect(0, 0, squareSize, squareSize), paint); return clippedBitmap; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Context context, Bitmap input, int pixels, int w, int h, boolean squareTL, boolean squareTR, boolean squareBL, boolean squareBR) { bitmapResult = Bitmap.createBitmap(w, h, Config.ARGB_8888); Canvas canvas = new Canvas(bitmapResult); final float densityMultiplier = context.getResources().getDisplayMetrics().density; final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0 + 5, 0 + 5, w - 5, h - 5); final RectF rectF = new RectF(rect); // make sure that our rounded corner is scaled appropriately final float roundPx = pixels * densityMultiplier; paint.setAntiAlias(true);/*from w w w .j ava 2 s.c om*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); // canvas.drawColor(Color.BLACK); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); // draw rectangles over the corners we want to be square if (squareTL) { canvas.drawRect(0, 0, w / 2, h / 2, paint); } if (squareTR) { canvas.drawRect(w / 2, 0, w, h / 2, paint); } if (squareBL) { canvas.drawRect(0, h / 2, w / 2, h, paint); } if (squareBR) { canvas.drawRect(w / 2, h / 2, w, h, paint); } paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // paint.setXfermode(new AvoidXfermode(Color.WHITE, 255, // AvoidXfermode.Mode.TARGET)); canvas.drawBitmap(input, 0, 0, paint); return bitmapResult; }
From source file:Main.java
public static Bitmap transferMode(Bitmap src, Bitmap mask, Xfermode xfermode) { final int width = mask.getWidth(); final int height = mask.getHeight(); final Bitmap dst = Bitmap.createBitmap(width, height, Config.ARGB_8888); final Canvas canvas = new Canvas(dst); final Paint paint = new Paint(); paint.setAntiAlias(true);// w w w.j ava 2 s . c om final int srcWidth = src.getWidth(); final int srcHeight = src.getHeight(); canvas.save(); // Scale down the image first if required. if ((width < srcWidth) || (height < srcHeight)) { float radioX = (float) width / srcWidth; float radioY = (float) height / srcHeight; float radio = 1f; float dx = 0f; float dy = 0f; if (radioX > radioY) { radio = radioX; dy = (height / radioX - srcHeight) / 2.0f; } else { radio = radioY; dx = (width / radioX - srcWidth) / 2.0f; } canvas.scale(radio, radio); canvas.translate(dx, dy); } canvas.drawBitmap(src, 0, 0, paint); canvas.restore(); if (xfermode != null) { paint.setXfermode(xfermode); canvas.drawBitmap(mask, 0, 0, paint); } return dst; }
From source file:nu.yona.app.utils.AppUtils.java
/** * Gets circle bitmap.//from w w w . j a va 2s . c om * * @param bitmap the bitmap * @return the circle bitmap */ public static Bitmap getCircleBitmap(Bitmap bitmap) { final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final int color = Color.BLUE; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; }
From source file:com.ibuildapp.romanblack.FanWallPlugin.data.Statics.java
/** * Sets the downloaded avatar.//ww w . j a va 2 s .c o m * * @param rawBitmap bitmap to round corners */ public static Bitmap publishAvatar(Bitmap rawBitmap, int roundK) { if (rawBitmap == null) return null; try { int size = 0; if (rawBitmap.getHeight() > rawBitmap.getWidth()) { size = rawBitmap.getWidth(); } else { size = rawBitmap.getHeight(); } Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, size, size); final RectF rectF = new RectF(rect); final float roundPx = roundK; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(rawBitmap, rect, rect, paint); rawBitmap.recycle(); return output; } catch (Exception e) { } return null; }
From source file:com.ibuildapp.romanblack.FanWallPlugin.data.Statics.java
/** * Sets the downloaded avatar.//www. j av a 2s . c om * * @param filePath file path to avatar image */ public static Bitmap publishAvatar(String filePath) { Bitmap bitmap = null; if (!TextUtils.isEmpty(filePath)) { try { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inSampleSize = 1; bitmap = BitmapFactory.decodeFile(filePath, opts); int size = 0; if (bitmap.getHeight() > bitmap.getWidth()) { size = bitmap.getWidth(); } else { size = bitmap.getHeight(); } Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, size, size); final RectF rectF = new RectF(rect); final float roundPx = 12; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; } catch (Exception e) { } } return null; }
From source file:Main.java
public static Bitmap getCircleBitmap(Bitmap bitmap) { final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final int color = Color.RED; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); //final Paint paintBorder = new Paint(); // paintBorder.setColor(Color.GREEN); //paintBorder.setShadowLayer(4.0f, 0.0f, 2.0f, Color.BLACK); //BitmapShader shader = new BitmapShader(Bitmap.createScaledBitmap(output, canvas.getWidth(), canvas.getHeight(), false), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); //paint.setShader(shader); paint.setAntiAlias(true);//from w w w . j a va2s. com //paintBorder.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawOval(rectF, paint); //int circleCenter = bitmap.getWidth() / 2; //int borderWidth = 2; //canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter + borderWidth - 4.0f, paintBorder); //canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter - 4.0f, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); //canvas.drawBitmap(bitmap, circleCenter + borderWidth, circleCenter + borderWidth, paint); bitmap.recycle(); return output; }