Example usage for android.graphics Path Path

List of usage examples for android.graphics Path Path

Introduction

In this page you can find the example usage for android.graphics Path Path.

Prototype

public Path() 

Source Link

Document

Create an empty path

Usage

From source file:Main.java

public static Bitmap GetBitmapClippedCircle(Bitmap bitmap) {

    final int width = bitmap.getWidth();
    final int height = bitmap.getHeight();
    final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    final Path path = new Path();
    path.addCircle((float) (width / 2), (float) (height / 2), (float) Math.min(width, (height / 2)),
            Path.Direction.CCW);//from w  ww.  j  a v  a  2s.  co m

    final Canvas canvas = new Canvas(outputBitmap);
    canvas.clipPath(path);
    canvas.drawBitmap(bitmap, 0, 0, null);
    return outputBitmap;
}

From source file:Main.java

/**
 * Helper method to draw a generic triangle onto the canvas
 * @param canvas the canvas being drawn to
 * @param a point 1// w w w .j a v  a  2  s  .  co  m
 * @param b point 2
 * @param c point 3
 */
public static void drawTriangle(Canvas canvas, Point a, Point b, Point c, Paint paint) {

    Path path = new Path();
    path.setFillType(Path.FillType.EVEN_ODD);
    path.moveTo(b.x, b.y);
    path.lineTo(c.x, c.y);
    path.lineTo(a.x, a.y);
    path.close();

    canvas.drawPath(path, paint);
}

From source file:Main.java

public static Bitmap GetBitmapClippedCircle(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Path path = new Path();
    path.addCircle((float) (width / 2), (float) (height / 2), (float) Math.min(width, (height / 2)),
            Path.Direction.CCW);//from  w w  w  . j  a  v a  2s .c  o m

    Canvas canvas = new Canvas(outputBitmap);
    canvas.clipPath(path);
    canvas.drawBitmap(bitmap, 0, 0, null);
    return outputBitmap;
}

From source file:Main.java

public static Bitmap getRoundedShape(Bitmap scaleBitmapImage, int width) {
    // TODO Auto-generated method stub
    int targetWidth = width;
    int targetHeight = width;
    Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(targetBitmap);
    Path path = new Path();
    path.addCircle(((float) targetWidth - 1) / 2, ((float) targetHeight - 1) / 2,
            (Math.min(((float) targetWidth), ((float) targetHeight)) / 2), Path.Direction.CCW);
    canvas.clipPath(path);//  w  w w.  j  av a2s . c  om
    Bitmap sourceBitmap = scaleBitmapImage;
    canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()),
            new Rect(0, 0, targetWidth, targetHeight), null);
    return targetBitmap;
}

From source file:Main.java

public static Bitmap getCircleBitmap(Context context, Bitmap src, float radius) {
    radius = dipTopx(context, radius);//from w  w w  . j ava 2s .c  o  m
    int w = src.getWidth();
    int h = src.getHeight();
    int canvasW = Math.round(radius * 2);
    Bitmap bitmap = Bitmap.createBitmap(canvasW, canvasW, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Path path = new Path();
    path.addCircle(radius, radius, radius, Path.Direction.CW);
    canvas.clipPath(path);

    Paint paint = new Paint();
    paint.setAntiAlias(true);

    Rect srcRect = new Rect(0, 0, w, h);
    Rect dstRect = new Rect(0, 0, canvasW, canvasW);

    canvas.drawBitmap(src, srcRect, dstRect, paint);

    return bitmap;
}

From source file:Main.java

/**
 * Get a circular (rounded) bitmap shape with the diameter is the smaller between target width and target height.
 * @param bitmap//from w  w w  .  j  a v a2 s.  c om
 * @param width target width
 * @param height target height
 * @return Rounded (circular) bitmap width diameter is the smaller between target width and target height.
 */
public static Bitmap getRoundedBitmap(Bitmap bitmap, int width, int height) {
    int diameter = width < height ? width : height;
    Bitmap targetBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(targetBitmap);
    Path path = new Path();
    path.addCircle(width / 2f, height / 2f, diameter / 2f, Path.Direction.CCW);
    canvas.clipPath(path);

    Bitmap sourceBitmap = bitmap;
    Rect destinationRect = new Rect(0, 0, width, height);
    Rect sourceRect = new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight());
    canvas.drawBitmap(sourceBitmap, sourceRect, destinationRect, null);
    return targetBitmap;
}

From source file:Main.java

/**
 * Returns a rounded bitmap using specified bitmap image.
 * //from  w w w. j av a  2s  .  com
 * @param scaleBitmapImage bitmap to make round image.
 * @return rounded bitmap
 */
public static Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
    if (scaleBitmapImage == null)
        return null;

    int targetWidth = (int) DP;
    int targetHeight = (int) DP;
    Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(targetBitmap);
    Path path = new Path();

    path.addCircle(((float) targetWidth - 1) / 2, ((float) targetHeight - 1) / 2,
            (Math.min(((float) targetWidth), ((float) targetHeight)) / 2),

            Path.Direction.CCW);

    Paint p = new Paint();
    p.setAntiAlias(true);

    canvas.clipPath(path);
    canvas.drawBitmap(scaleBitmapImage,
            new Rect(0, 0, scaleBitmapImage.getWidth(), scaleBitmapImage.getHeight()),
            new Rect(0, 0, targetWidth, targetHeight), p);

    p.setARGB(255, 16, 18, 16);

    scaleBitmapImage.recycle();

    return targetBitmap;
}

From source file:Main.java

private static Path drawPaddingLeft() {
    //Draw the padding Left
    Path paddingLeft = new Path();
    paddingLeft.moveTo(coord_A[0], coord_A[1]); /*A*/
    paddingLeft.lineTo(coord_B[0], coord_B[1]); /*B*/
    paddingLeft.lineTo(coord_C[0], coord_C[1]); /*C*/
    paddingLeft.lineTo(coord_D[0], coord_D[1]); /*D*/
    paddingLeft.lineTo(coord_E[0], coord_E[1]); /*E*/
    paddingLeft.lineTo(coord_F[0], coord_F[1]); /*F*/
    paddingLeft.close();//from   w ww  .j a va 2s  . c  o  m

    return paddingLeft;
}

From source file:Main.java

private static Path drawPaddingRight() {
    //Draw the padding Right
    Path paddingRight = new Path();
    paddingRight.moveTo(coord_A[0], coord_A[1]); /*A*/
    paddingRight.lineTo(coord_F[0], coord_F[1]); /*F*/
    paddingRight.lineTo(coord_G[0], coord_G[1]); /*G*/
    paddingRight.lineTo(coord_H[0], coord_H[1]); /*H*/
    paddingRight.lineTo(coord_I[0], coord_I[1]); /*I*/
    paddingRight.lineTo(coord_J[0], coord_J[1]); /*J*/
    paddingRight.close();//from  ww w.  ja va 2  s .co m

    return paddingRight;
}

From source file:Main.java

private static void drawRoundRect(Canvas canvas, RectF rect, Paint paint, int radius, boolean leftTop,
        boolean rightTop, boolean leftBottom, boolean rightBottom) {
    float roundRadius[] = new float[8];
    roundRadius[0] = leftTop ? 0 : radius;
    roundRadius[1] = leftTop ? 0 : radius;
    roundRadius[2] = rightTop ? 0 : radius;
    roundRadius[3] = rightTop ? 0 : radius;
    roundRadius[4] = rightBottom ? 0 : radius;
    roundRadius[5] = rightBottom ? 0 : radius;
    roundRadius[6] = leftBottom ? 0 : radius;
    roundRadius[7] = leftBottom ? 0 : radius;

    Path path = new Path();
    path.addRoundRect(rect, roundRadius, Direction.CCW);
    canvas.drawPath(path, paint);//from   ww  w.  j a  v  a 2  s  . c  o  m
}