List of usage examples for android.graphics Paint Paint
public Paint()
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), 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); final float roundPx = 12; paint.setAntiAlias(true);/*from ww w . ja v a 2s . c o m*/ 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); if (null != bitmap) { bitmap.recycle(); bitmap = null; } return output; }
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. ja v a 2 s. c om*/ //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; }
From source file:Main.java
public static Bitmap getRCB(Bitmap bitmap, float roundPX) { // RCB means/* w w w. j a va 2 s . co m*/ // Rounded // Corner Bitmap Bitmap dstbmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(dstbmp); 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, roundPX, roundPX, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return dstbmp; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); float roundPx = w / 2; Bitmap output = Bitmap.createBitmap(w, h, 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, w, h); final RectF rectF = new RectF(rect); paint.setAntiAlias(true);/*from w w w . j a v a 2s. c o m*/ 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); return output; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { try {/*from w w w . j ava 2 s.com*/ Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), 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, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; } catch (Exception e) { e.printStackTrace(); return bitmap; } }
From source file:Main.java
public static Bitmap getMosaic(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); int radius = 10; Bitmap mosaicBitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(mosaicBitmap); int horCount = (int) Math.ceil(width / (float) radius); int verCount = (int) Math.ceil(height / (float) radius); Paint paint = new Paint(); paint.setAntiAlias(true);//from w w w .j ava 2s .co m for (int horIndex = 0; horIndex < horCount; ++horIndex) { for (int verIndex = 0; verIndex < verCount; ++verIndex) { int l = radius * horIndex; int t = radius * verIndex; int r = l + radius; if (r > width) { r = width; } int b = t + radius; if (b > height) { b = height; } int color = bitmap.getPixel(l, t); Rect rect = new Rect(l, t, r, b); paint.setColor(color); canvas.drawRect(rect, paint); } } canvas.save(); return mosaicBitmap; }
From source file:Main.java
public static Bitmap createRoundCornerBitmap(Bitmap bitmap, float roundPx) { Bitmap roundCornerBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);/*w w w.j av a2 s. c om*/ Canvas canvas = new Canvas(roundCornerBitmap); Paint paint = new Paint(); Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); RectF rectF = new RectF(rect); int color = 0xff424242; 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 roundCornerBitmap; }
From source file:Main.java
/** * Method to get a rounded rectange bitmap * @param bitmap//from w w w . j av a2 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
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 ww. ja v a 2s . co m 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 createScreenshot4(View view, int thumbnailWidth, int thumbnailHeight) { if (view != null) { Bitmap mCapture;/*from w w w . j a v a 2s . c om*/ try { mCapture = Bitmap.createBitmap(thumbnailWidth, thumbnailHeight, Bitmap.Config.RGB_565); } catch (OutOfMemoryError e) { return null; } Canvas c = new Canvas(mCapture); Paint transPainter = new Paint(); transPainter.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); c.drawRect(0, 0, mCapture.getWidth(), mCapture.getHeight(), transPainter); try { view.draw(c); } catch (Exception e) { } return mCapture; } return null; }