List of usage examples for android.graphics Paint Paint
public Paint()
From source file:Main.java
public static void drawRuleOfThird(Canvas canvas, RectF bounds) { Paint p = new Paint(); p.setStyle(Paint.Style.STROKE); p.setColor(Color.argb(128, 255, 255, 255)); p.setStrokeWidth(2);/*ww w . j av a2 s .c om*/ float stepX = bounds.width() / 3.0f; float stepY = bounds.height() / 3.0f; float x = bounds.left + stepX; float y = bounds.top + stepY; for (int i = 0; i < 2; i++) { canvas.drawLine(x, bounds.top, x, bounds.bottom, p); x += stepX; } for (int j = 0; j < 2; j++) { canvas.drawLine(bounds.left, y, bounds.right, y, p); y += stepY; } }
From source file:Main.java
public static Bitmap roundCornerFromFile(String filePath, int pixels) { try {//from w w w.jav a 2 s . c o m Bitmap bitmap = BitmapFactory.decodeFile(filePath); if (bitmap == null) return null; Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); 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); 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); bitmap.recycle(); bitmap = null; return output; } catch (OutOfMemoryError e) { return null; } catch (Exception e) { return null; } }
From source file:Main.java
/** * Return rounded bitmap with top left corner as rounded using specified bitmap and bitmap size in pixels. * //from w ww . jav a 2 s. co m * @param bitmap to make rounded * @param pixels size of bitmap * @return slightly rounded bitmap. */ public static Bitmap getRoundedTopLeftCornerBitmap(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; final Rect topRightRect = new Rect(bitmap.getWidth() / 2, 0, bitmap.getWidth(), bitmap.getHeight() / 2); final Rect bottomRect = new Rect(0, bitmap.getHeight() / 2, bitmap.getWidth(), bitmap.getHeight()); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); // Fill in upper right corner canvas.drawRect(topRightRect, paint); // Fill in bottom corners canvas.drawRect(bottomRect, 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, 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);// ww w .j a va2 s.c o m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, (float) pixels, (float) 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(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 = 50; paint.setAntiAlias(true);/*from www.j ava2 s.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); return output; }
From source file:Main.java
public static Bitmap tintBitmap(Bitmap src, int color) { Paint paint = new Paint(); paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)); Bitmap dst = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(dst); canvas.drawBitmap(src, 0, 0, paint); return dst;/*from w w w .j a v a 2 s.co m*/ }
From source file:Main.java
private static void initPaint() { mPaint = new Paint(); mPaint.setAntiAlias(true);/*from ww w .j a va 2s.co m*/ mPaint.setColor(mLineColor); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(mLineWidth); mPaint.setStrokeCap(Paint.Cap.ROUND); }
From source file:Main.java
public static void cleanCanvas(Canvas mCanvas) { if (mCanvas != null) { Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); mCanvas.drawPaint(paint);/*from w w w . ja v a 2 s .c o m*/ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); mCanvas = null; } }
From source file:Main.java
/** * Creates the Paint object for drawing the crop window guidelines. * /* w ww. j a v a 2s.c o m*/ * @return the new Paint object */ public static Paint newRotateBottomImagePaint() { final Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setStrokeWidth(3); return paint; }
From source file:Main.java
public static Bitmap getCircularBitmap(Bitmap srcBitmap) { // Calculate the circular bitmap width with border int squareBitmapWidth = Math.min(srcBitmap.getWidth(), srcBitmap.getHeight()); //int squareBitmapWidth = 300; // Initialize a new instance of Bitmap Bitmap dstBitmap = Bitmap.createBitmap(squareBitmapWidth, // Width squareBitmapWidth, // Height Bitmap.Config.ARGB_8888 // Config );//from w w w.j av a2s . c o m Canvas canvas = new Canvas(dstBitmap); // Initialize a new Paint instance Paint paint = new Paint(); paint.setAntiAlias(true); Rect rect = new Rect(0, 0, squareBitmapWidth, squareBitmapWidth); RectF rectF = new RectF(rect); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // Calculate the left and top of copied bitmap float left = (squareBitmapWidth - srcBitmap.getWidth()) / 2; float top = (squareBitmapWidth - srcBitmap.getHeight()) / 2; canvas.drawBitmap(srcBitmap, left, top, paint); srcBitmap.recycle(); return dstBitmap; }