List of usage examples for android.graphics PorterDuffXfermode PorterDuffXfermode
public PorterDuffXfermode(PorterDuff.Mode mode)
From source file:com.wareninja.opensource.gravatar4android.common.Utils.java
public static Bitmap getBitmapWithReflection(Bitmap originalImage) { //The gap we want between the reflection and the original image final int reflectionGap = 4; int width = originalImage.getWidth(); int height = originalImage.getHeight(); //This will not scale but will flip on the Y axis Matrix matrix = new Matrix(); matrix.preScale(1, -1);//ww w . ja va 2 s . com //Create a Bitmap with the flip matrix applied to it. //We only want the bottom half of the image Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width, height / 2, matrix, false); //Create a new bitmap with same width but taller to fit reflection Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888); //Create a new Canvas with the bitmap that's big enough for //the image plus gap plus reflection Canvas canvas = new Canvas(bitmapWithReflection); //Draw in the original image canvas.drawBitmap(originalImage, 0, 0, null); //Draw in the gap Paint deafaultPaint = new Paint(); canvas.drawRect(0, height, width, height + reflectionGap, deafaultPaint); //Draw in the reflection canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); //Create a shader that is a linear gradient that covers the reflection Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); //Set the paint to use this shader (linear gradient) 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; }
From source file:com.ibuildapp.romanblack.FanWallPlugin.data.Statics.java
/** * Sets the downloaded avatar.//from w ww. ja v a2 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:net.archenemy.archenemyapp.presenter.BitmapUtility.java
/** * Transforms a bitmap into a circle shape. * /* w ww .ja va 2 s. c om*/ * @param bitmap * @param pixels * @return bitmap as circle shape */ public static Bitmap getCircleBitmap(Bitmap bitmap, int diameterPixels) { if (bitmap != null) { final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); final 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 = diameterPixels; 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; } return null; }
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:// www. j a v a 2s. c o 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:com.chalmers.feedlr.adapter.FeedAdapter.java
/** * /*from www . ja va 2s. com*/ * @param squareBitmap * original image * @return image with rounded corners */ public static Bitmap getRoundedCornerBitmap(Bitmap squareBitmap) { Bitmap roundedBitmap = Bitmap.createBitmap(squareBitmap.getWidth(), squareBitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(roundedBitmap); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, squareBitmap.getWidth(), squareBitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = 8; 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(squareBitmap, rect, rect, paint); return roundedBitmap; }
From source file:cc.softwarefactory.lokki.android.utilities.Utils.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float pixels) { if (bitmap == null) { Log.e(TAG, "getRoundedCornerBitmap - null bitmap"); return null; }/*from w ww . ja va2 s .com*/ 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:com.gj.administrator.gjerp.view.CircleIndicator.java
private void createMovingItem() { OvalShape circle = new OvalShape(); ShapeDrawable drawable = new ShapeDrawable(circle); movingItem = new ShapeHolder(drawable); Paint paint = drawable.getPaint(); paint.setColor(mIndicatorSelectedBackground); paint.setAntiAlias(true);//from ww w.j a v a 2 s. c om switch (mIndicatorMode) { case INSIDE: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP)); break; case OUTSIDE: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); break; case SOLO: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); break; } movingItem.setPaint(paint); }
From source file:id.satusatudua.sigap.ui.fragment.GuardingLocationFragment.java
private 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); paint.setAntiAlias(true);/*from w ww .ja v a 2 s . co m*/ 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:csci310.parkhere.ui.fragments.PublicProfileFragment.java
public static Bitmap getRoundedBitmap(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); paint.setAntiAlias(true);/*from w w w . ja v a2 s . c om*/ 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.cooltechworks.views.ScratchImageView.java
/** * clears the scratch area to reveal the hidden image. *//*from w ww .ja va2s .com*/ public void clear() { int[] bounds = getImageBounds(); int left = bounds[0]; int top = bounds[1]; int right = bounds[2]; int bottom = bounds[3]; int width = right - left; int height = bottom - top; int centerX = left + width / 2; int centerY = top + height / 2; left = centerX - width / 2; top = centerY - height / 2; right = left + width; bottom = top + height; Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); mCanvas.drawRect(left, top, right, bottom, paint); checkRevealed(); invalidate(); }