List of usage examples for android.graphics Path Path
public Path()
From source file:Main.java
/** * Returns a path with a given set of peeks in a 'randomly' handrawn style * /*from w ww.j a va2 s. c om*/ * @param peek_x * array of X locations of the peeks * @param peek_y * array of Y locations of the peeks * @return constructed path */ public static Path peeks(float[] peek_x, float[] peek_y, float offset) { final Path p = new Path(); p.moveTo(-offset, 0); float diff = 0; float cdiff = 0; int cp = 0; for (float x = -offset + RESOLUTION; x < 1 + offset; x += RESOLUTION) { if (x >= peek_x[cp]) { if (cp == peek_x.length - 1) { diff = 0; cdiff = 0; } else { diff = (peek_y[cp] - peek_y[cp + 1]) / ((peek_x[cp + 1] - peek_x[cp]) / RESOLUTION); if (diff == 0) { cdiff = 0; } ++cp; } } cdiff += diff; float to_y = cdiff + (randomizer.nextBoolean() ? 1 : -1) * randomizer.nextFloat() * (diff == 0 ? 0.003f : 0.01f); if (to_y < -MAX) { to_y = 0; } p.lineTo(x, -to_y); } p.lineTo(1 + offset, 0); return p; }
From source file:Main.java
public static Path createCommentShape(int x, int y, int width, int height, boolean no_bottom) { Path gp = new Path(); int arc = 4;// w w w. j av a 2s. c om if (no_bottom == true) { gp.moveTo(0, height); gp.lineTo(0, 5 + arc); } else { gp.moveTo(0, 5 + arc); } gp.quadTo(0, 5, arc, 5); gp.lineTo(15, 5); gp.lineTo(20, 0); gp.lineTo(25, 5); gp.lineTo(width - arc, 5); gp.quadTo(width, 5, width, 5 + arc); gp.lineTo(width, height - arc); if (no_bottom) { gp.lineTo(width, height); } else { gp.quadTo(width, height, width - arc, height); gp.lineTo(arc, height); gp.quadTo(0, height, 0, height - arc); gp.lineTo(0, 5 + arc); } return gp; }
From source file:Main.java
private static Path drawPadding() { //Draw the padding Path padding = new Path(); padding.moveTo(coord_A[2], coord_A[3]); /*A*/ padding.lineTo(coord_B[2], coord_B[3]); /*B*/ padding.lineTo(coord_C[2], coord_C[3]); /*C*/ padding.lineTo(coord_D[2], coord_D[3]); /*D*/ padding.lineTo(coord_E[2], coord_E[3]); /*E*/ padding.lineTo(coord_F[2], coord_F[3]); /*F*/ padding.lineTo(coord_G[2], coord_G[3]); /*G*/ padding.lineTo(coord_H[2], coord_H[3]); /*H*/ padding.lineTo(coord_I[2], coord_I[3]); /*I*/ padding.lineTo(coord_J[2], coord_J[3]); /*J*/ padding.close();//from w w w .j a v a2 s .co m return padding; }
From source file:Main.java
private static Path drawOutLine() { //Draw the outline Path outline = new Path(); outline.moveTo(coord_A[0], coord_A[1]); /*A*/ outline.lineTo(coord_B[0], coord_B[1]); /*B*/ outline.lineTo(coord_C[0], coord_C[1]); /*C*/ outline.lineTo(coord_D[0], coord_D[1]); /*D*/ outline.lineTo(coord_E[0], coord_E[1]); /*E*/ outline.lineTo(coord_F[0], coord_F[1]); /*F*/ outline.lineTo(coord_G[0], coord_G[1]); /*G*/ outline.lineTo(coord_H[0], coord_H[1]); /*H*/ outline.lineTo(coord_I[0], coord_I[1]); /*I*/ outline.lineTo(coord_J[0], coord_J[1]); /*J*/ outline.moveTo(coord_A[2], coord_A[3]); /*A*/ outline.lineTo(coord_B[2], coord_B[3]); /*J*/ outline.lineTo(coord_C[2], coord_C[3]); /*I*/ outline.lineTo(coord_D[2], coord_D[3]); /*H*/ outline.lineTo(coord_E[2], coord_E[3]); /*G*/ outline.lineTo(coord_F[2], coord_F[3]); /*F*/ outline.lineTo(coord_G[2], coord_G[3]); /*E*/ outline.lineTo(coord_H[2], coord_H[3]); /*D*/ outline.lineTo(coord_I[2], coord_I[3]); /*C*/ outline.lineTo(coord_J[2], coord_J[3]); /*B*/ outline.close();/* ww w.ja v a 2 s. c om*/ return outline; }
From source file:Main.java
/**Method to get round shaped bitmap. Mostly used for profile pictures * * @param scaleBitmapImage/*from w ww . j a va2 s . c o m*/ * The source bitmap which has to converted to round shape * @param context * The context * @param targetWidthPixels * The width required for the target or returned bitmap * @param targetHeightPixels * The height required for the target or returned bitmap * @return * round shaped bitmap */ public static Bitmap getRoundedShape(Bitmap scaleBitmapImage, Context context, int targetWidthPixels, int targetHeightPixels) { Bitmap targetBitmap = Bitmap.createBitmap(targetWidthPixels, targetHeightPixels, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(targetBitmap); Path path = new Path(); path.addCircle(((float) targetWidthPixels - 1) / 2, ((float) targetHeightPixels - 1) / 2, (Math.min(((float) targetWidthPixels), ((float) targetHeightPixels)) / 2), Path.Direction.CCW); canvas.clipPath(path); Bitmap sourceBitmap = scaleBitmapImage; canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()), new Rect(0, 0, targetWidthPixels, targetHeightPixels), null); return targetBitmap; }
From source file:Main.java
/** * Crop bitmap image into a round shape/*from ww w. j a v a2 s. c o m*/ * * @param bitmap the bitmap * @param diameter the diameter of the resulting image * @return the rounded bitmap */ private static Bitmap getRoundedShape(@NonNull Bitmap bitmap, int diameter) { Bitmap resultBitmap = Bitmap.createBitmap(diameter, diameter, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(resultBitmap); Path path = new Path(); path.addCircle(((float) diameter - 1) / 2, ((float) diameter - 1) / 2, (((float) diameter) / 2), Path.Direction.CCW); canvas.clipPath(path); resultBitmap.setHasAlpha(true); canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), new Rect(0, 0, diameter, diameter), null); return resultBitmap; }
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.//ww w . ja va 2 s. c o 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);/*from w ww . java 2s .co m*/ 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); 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
private static Path gloss(int size) { Path gloss = new Path(); gloss.moveTo(0, size);//from w ww.ja v a2 s .c o m gloss.cubicTo(0, size, size * 3 / 4, size * 3 / 4, size, 0); gloss.lineTo(0, 0); gloss.close(); return gloss; }
From source file:Main.java
public static void drawWallpaperSelectionFrame(Canvas canvas, RectF cropBounds, float spotX, float spotY, Paint p, Paint shadowPaint) { float sx = cropBounds.width() * spotX; float sy = cropBounds.height() * spotY; float cx = cropBounds.centerX(); float cy = cropBounds.centerY(); RectF r1 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2); float temp = sx; sx = sy;/*from w ww. j a va2 s .co m*/ sy = temp; RectF r2 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2); canvas.save(); canvas.clipRect(cropBounds); canvas.clipRect(r1, Region.Op.DIFFERENCE); canvas.clipRect(r2, Region.Op.DIFFERENCE); canvas.drawPaint(shadowPaint); canvas.restore(); Path path = new Path(); path.moveTo(r1.left, r1.top); path.lineTo(r1.right, r1.top); path.moveTo(r1.left, r1.top); path.lineTo(r1.left, r1.bottom); path.moveTo(r1.left, r1.bottom); path.lineTo(r1.right, r1.bottom); path.moveTo(r1.right, r1.top); path.lineTo(r1.right, r1.bottom); path.moveTo(r2.left, r2.top); path.lineTo(r2.right, r2.top); path.moveTo(r2.right, r2.top); path.lineTo(r2.right, r2.bottom); path.moveTo(r2.left, r2.bottom); path.lineTo(r2.right, r2.bottom); path.moveTo(r2.left, r2.top); path.lineTo(r2.left, r2.bottom); canvas.drawPath(path, p); }