List of usage examples for android.graphics Paint Paint
public Paint()
From source file:Main.java
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) { 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 = pixels; paint.setAntiAlias(true);/* w ww . ja v a 2 s .co 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); 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.WHITE; 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 o 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: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);//from ww w .j av a2 s. co m 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; }
From source file:Main.java
public static Bitmap circleCrop(Bitmap bitmap) { int size = Math.min(bitmap.getWidth(), bitmap.getHeight()); Bitmap output = Bitmap.createBitmap(size, size, 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); paint.setAntiAlias(true);/* w w w. ja v a 2 s . c om*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); // canvas.drawRoundRect(rectF, roundPx, roundPx, paint); canvas.drawCircle(size / 2, size / 2, size / 2, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); // Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false); // return _bmp; return output; }
From source file:Main.java
public static Bitmap addLabelToBitmap(Bitmap src, String label) { float densityFactor = Resources.getSystem().getDisplayMetrics().density; final float textPadding = src.getWidth() * 0.05f; Bitmap result = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); Paint textPaint = new Paint(); textPaint.setAntiAlias(true);/*from w ww.ja v a 2 s. c o m*/ textPaint.setTextSize(12 * densityFactor); textPaint.setColor(Color.WHITE); textPaint.setStrokeWidth(2 * densityFactor); textPaint.setShadowLayer(1 * densityFactor, 0, 0, Color.BLACK); float textWidth = textPaint.measureText(label); float scaleFactor = (src.getWidth() - textPadding * 2) / textWidth; canvas.drawBitmap(src, 0, 0, textPaint); canvas.save(); canvas.scale(scaleFactor, scaleFactor); float textPosX = (src.getWidth() / scaleFactor - textWidth) / 2; float textPosY = (src.getHeight() - textPadding) / scaleFactor; canvas.drawText(label, textPosX, textPosY, textPaint); canvas.restore(); return result; }
From source file:Main.java
static private Bitmap smallCoverPostProc(Bitmap smallBitmap) { try {/* w w w . j a v a 2s. c o m*/ Bitmap smallBitmapPostProc = Bitmap.createBitmap(smallBitmap.getWidth(), smallBitmap.getHeight(), Bitmap.Config.RGB_565); Canvas canvas = new Canvas(); canvas.setBitmap(smallBitmapPostProc); Paint paint = new Paint(); paint.setAntiAlias(true); Bitmap bitmapToShade = Bitmap.createBitmap(smallBitmap, 2, 2, smallBitmap.getWidth() - 4, smallBitmap.getHeight() - 4); BitmapShader bmShader = new BitmapShader(bitmapToShade, TileMode.CLAMP, TileMode.CLAMP); paint.setShader(bmShader); canvas.drawRoundRect(new RectF(2, 2, smallBitmap.getWidth() - 2, smallBitmap.getHeight() - 2), 4, 4, paint); return smallBitmapPostProc; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static Bitmap makeRoundedCornerBitmap(Bitmap bitmap, float roundPx) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Bitmap output = Bitmap.createBitmap(w, h, 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 www. j av a 2 s . com*/ 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; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, final float roundPx) { if (bitmap == null) return null; try {//from w w w.ja v a 2 s. co m Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight())); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.BLACK); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); final Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawBitmap(bitmap, src, rect, paint); return output; } catch (Exception e) { return bitmap; } }
From source file:Main.java
public static Bitmap cropJpgFile(String inFl, String outFl) throws IOException { Bitmap bmpIn = BitmapFactory.decodeFile(inFl); Bitmap bmOverlay = Bitmap.createBitmap(bmpIn.getWidth(), bmpIn.getHeight(), Bitmap.Config.ARGB_8888); Paint p = new Paint(); p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); Canvas c = new Canvas(bmOverlay); c.drawBitmap(bmpIn, 0, 0, null);/*from w w w . j a v a 2 s .co m*/ //c.drawRect(30, 30, 100, 100, p); File fileOut = new File(outFl); FileOutputStream out = new FileOutputStream(fileOut); bmOverlay = drawTextToBitmap(bmOverlay, "Image Viewer"); bmOverlay.compress(Bitmap.CompressFormat.JPEG, 100, out); return bmOverlay; }
From source file:Main.java
public static Bitmap getTextImage(String text, float size, int width, int height) { final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Paint paint = new Paint(); final Canvas canvas = new Canvas(bmp); canvas.drawColor(Color.WHITE); paint.setColor(Color.BLACK);/*from ww w .j a v a 2 s . c o m*/ paint.setStyle(Style.FILL); paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER); paint.setTextSize(size); paint.setTypeface(Typeface.DEFAULT); canvas.drawText(text, width / 2, height / 2, paint); return bmp; }