List of usage examples for android.graphics Paint setFilterBitmap
public void setFilterBitmap(boolean filter)
From source file:Main.java
/** * * @return//w w w . jav a2 s. co m */ public static Paint newPaint() { Paint paint = new Paint(1); paint.setFilterBitmap(true); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); return paint; }
From source file:Main.java
public static Bitmap createScaledBitmap(Bitmap bitmap, int width, int height) { Bitmap background = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888); float originalWidth = bitmap.getWidth(), originalHeight = bitmap.getHeight(); Canvas canvas = new Canvas(background); float scale = Math.max(width / originalWidth, height / originalHeight); float xTranslation = 0.0f, yTranslation = (height - originalHeight * scale) / 2.0f; if (originalWidth < originalHeight) { // scale = height / originalHeight; xTranslation = (width - originalWidth * scale) / 2.0f; yTranslation = 0.0f;/* www . j a va 2 s . com*/ } Matrix transformation = new Matrix(); transformation.postTranslate(xTranslation, yTranslation); transformation.preScale(scale, scale); Paint paint = new Paint(); paint.setFilterBitmap(true); canvas.drawBitmap(bitmap, transformation, paint); return background; }
From source file:Main.java
public static void drawCircleBorder(Canvas canvas, int radius, int w, int y) { Paint paint = new Paint(); paint.setAntiAlias(true);//from ww w . j a v a 2 s . c o m paint.setFilterBitmap(true); paint.setDither(true); paint.setColor(Color.WHITE); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(mBorderThickness); canvas.drawCircle(w / 2, y / 2, radius, paint); }
From source file:Main.java
public static Bitmap int2Icon(Context context, int i) { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), 0x7f020047); Bitmap bitmap1 = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), android.graphics.Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap1); Paint paint = new Paint(); paint.setDither(true);//from w ww . ja v a 2 s . c om paint.setFilterBitmap(true); canvas.drawBitmap(bitmap, 0.0F, 0.0F, paint); bitmap.recycle(); Paint paint1 = new Paint(257); paint1.setColor(-1); paint1.setTypeface(Typeface.DEFAULT_BOLD); paint1.setTextAlign(android.graphics.Paint.Align.CENTER); canvas.drawText(String.valueOf(i), bitmap.getWidth() / 2, 3 + bitmap.getHeight() / 2, paint1); return bitmap1; }
From source file:Main.java
/** * Use touch-icon or higher-resolution favicon and round the corners. * @param context Context used to get resources. * @param touchIcon Touch icon bitmap.//from www. j a v a 2 s. co m * @param canvas Canvas that holds the touch icon. */ private static void drawTouchIconToCanvas(Context context, Bitmap touchIcon, Canvas canvas) { Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); Rect src = new Rect(0, 0, touchIcon.getWidth(), touchIcon.getHeight()); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setFilterBitmap(true); canvas.drawBitmap(touchIcon, src, iconBounds, paint); // Convert dp to px. int borderRadii = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, TOUCHICON_BORDER_RADII, context.getResources().getDisplayMetrics()); Path path = new Path(); path.setFillType(Path.FillType.INVERSE_WINDING); RectF rect = new RectF(iconBounds); rect.inset(INSET_DIMENSION_FOR_TOUCHICON, INSET_DIMENSION_FOR_TOUCHICON); path.addRoundRect(rect, borderRadii, borderRadii, Path.Direction.CW); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); canvas.drawPath(path, paint); }
From source file:Main.java
private static void drawTouchIconToCanvas(Bitmap touchIcon, Canvas canvas, Rect iconBounds) { Rect src = new Rect(0, 0, touchIcon.getWidth(), touchIcon.getHeight()); // Paint used for scaling the bitmap and drawing the rounded rect. Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setFilterBitmap(true); canvas.drawBitmap(touchIcon, src, iconBounds, paint); // Construct a path from a round rect. This will allow drawing with // an inverse fill so we can punch a hole using the round rect. Path path = new Path(); path.setFillType(Path.FillType.INVERSE_WINDING); RectF rect = new RectF(iconBounds); rect.inset(1, 1);/* ww w . j av a2s.c om*/ path.addRoundRect(rect, 8f, 8f, Path.Direction.CW); // Reuse the paint and clear the outside of the rectangle. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); canvas.drawPath(path, paint); }
From source file:Main.java
static Bitmap generatorContactCountIcon(Context context, Bitmap icon) { int iconSize = (int) context.getResources().getDimension(android.R.dimen.app_icon_size); Bitmap contactIcon = Bitmap.createBitmap(iconSize, iconSize, Config.ARGB_8888); Canvas canvas = new Canvas(contactIcon); Paint iconPaint = new Paint(); iconPaint.setDither(true);// w w w . j a v a 2 s.c om iconPaint.setFilterBitmap(true); Rect src = new Rect(0, 0, icon.getWidth(), icon.getHeight()); Rect dst = new Rect(0, 0, iconSize, iconSize); canvas.drawBitmap(icon, src, dst, iconPaint); int contacyCount = 11; Paint countPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG); countPaint.setColor(Color.RED); countPaint.setTextSize(20f); countPaint.setTypeface(Typeface.DEFAULT_BOLD); canvas.drawText(String.valueOf(contacyCount), iconSize - 18, 25, countPaint); return contactIcon; }
From source file:Main.java
public static Bitmap getRoundImage(Bitmap oriImg, boolean recycleOld) { Bitmap targetBitmap = null;/*from w w w .j av a 2s . c o m*/ 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 createCircleBitmap(Bitmap bitmap) { if (bitmap == null) { return null; }//from w w w .j a v a 2 s .c om int bmWidth = bitmap.getWidth(); int bmHeight = bitmap.getHeight(); int side = bmWidth < bmHeight ? bmWidth : bmHeight; int x = (bmWidth - side) / 2; int y = (bmHeight - side) / 2; Bitmap newBm = Bitmap.createBitmap(side, side, Bitmap.Config.ARGB_8888); if (newBm != null) { Canvas canvas = new Canvas(newBm); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); Rect rect = new Rect(0, 0, newBm.getWidth(), newBm.getHeight()); canvas.drawARGB(0, 0, 0, 0); canvas.drawCircle(newBm.getWidth() / 2, newBm.getHeight() / 2, newBm.getHeight() / 2, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return newBm; } return null; }
From source file:Main.java
public static Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) { int sourceWidth = source.getWidth(); int sourceHeight = source.getHeight(); // Compute the scaling factors to fit the new height and width, respectively. // To cover the final image, the final scaling will be the bigger // of these two. float xScale = (float) newWidth / sourceWidth; float yScale = (float) newHeight / sourceHeight; float scale = Math.max(xScale, yScale); // Now get the size of the source bitmap when scaled float scaledWidth = scale * sourceWidth; float scaledHeight = scale * sourceHeight; // Let's find out the upper left coordinates if the scaled bitmap // should be centered in the new size give by the parameters float left = (newWidth - scaledWidth) / 2; float top = (newHeight - scaledHeight) / 2; // The target rectangle for the new, scaled version of the source bitmap will now // be/*from w ww . j a v a 2 s. co m*/ RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight); // Finally, we create a new bitmap of the specified size and draw our new, // scaled bitmap onto it. Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, CONFIG); Canvas canvas = new Canvas(dest); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); canvas.drawBitmap(source, null, targetRect, paint); return dest; }