path.setFillType(Path.FillType.EVEN_ODD); path.moveTo(point1_draw.x,point1_draw.y); path.lineTo(point2_draw.x,point2_draw.y);
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); paint.setColor(android.graphics.Color.BLACK); canvas.drawPaint(paint); paint.setStrokeWidth(4); paint.setColor(android.graphics.Color.RED); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setAntiAlias(true); Point a = new Point(0, 0); Point b = new Point(0, 100); Point c = new Point(87, 50); Path path = new Path(); path.setFillType(FillType.EVEN_ODD); path.lineTo(b.x, b.y); path.lineTo(c.x, c.y); path.lineTo(a.x, a.y); path.close(); canvas.drawPath(path, paint); }
final Path path = new Path(); final Paint paint = new Paint(); paint.setColor(Color.RED); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL_AND_STROKE); path.moveTo(100, 100); path.lineTo(200, 100); path.lineTo(200, 200); path.lineTo(100, 200); path.close(); path.moveTo(150, 150); path.lineTo(180, 150); path.lineTo(180, 180); path.lineTo(150, 180); path.close(); path.setFillType(Path.FillType.EVEN_ODD); canvas.drawPath(path, paint);
path.setFillType(Path.FillType.EVEN_ODD); path.setLastPoint(left.x, left.y); path.lineTo(right.x, right.y);
mPointer.setFillType(Path.FillType.EVEN_ODD);
Path invertedCircle = new Path(); int radius = (canvas.getWidth() < canvas.getHeight()) ? canvas .getWidth() / 4 : canvas.getHeight() / 2; invertedCircle.addCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, radius, Direction.CW); invertedCircle.setFillType(FillType.INVERSE_EVEN_ODD); Paint p = new Paint(); p.setColor(Color.BLACK); canvas.drawPath(invertedCircle, p);
class MyDrawable extends Drawable { @Override public void draw(Canvas canvas) { Path path = new Path(); path.setFillType(FillType.EVEN_ODD); // This will create a full screen rectangle. path.addRect(<screen size rect here>, Path.Direction.CW); // This will punch a hole in it path.addCircle(<x>, <y>, <radius>, Path.Direction.CCW); // Now draw everything on the Canvas Paint paint = new Paint(); paint.setColor(<dim color here>); canvas.drawPath(path, paint); }
// Limit the drawable region of the canvas (saving the state before) canvas.save(); canvas.clipRect(new Rect(0, canvas.getHeight() - 70, canvas.getWidth(), canvas.getHeight())); Path path = new Path(); path.setFillType(Path.FillType.INVERSE_EVEN_ODD); path.addCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, canvas.getHeight() / 2, Path.Direction.CW); path.addRect(0, canvas.getHeight() - 70, canvas.getWidth(), canvas.getHeight(), Path.Direction.CW); canvas.drawPath(path, paint); // Restore the canvas to the saved state to remove clip canvas.restore(); // Draw more things on the canvas...
Canvas canvas = new Canvas(bitmap); Paint innerCirclePaint; innerCirclePaint = new Paint(); innerCirclePaint.setColor(Color.parseColor ("#88ff0000")); innerCirclePaint.setAlpha(35); innerCirclePaint.setAntiAlias(true); innerCirclePaint.setStyle(Paint.Style.FILL); Path path = new Path(); path.setFillType(Path.FillType.INVERSE_WINDING); path.addCircle(150, 150, 150, Path.Direction.CCW); canvas.drawPath(path, innerCirclePaint); canvas.drawARGB(0, 0, 0, 0 ); canvas.clipPath(path);
Path outerPath = new Path(); // add rect covering the whole view area outerPath.addRect(0, 0, getWidth(), getHeight(), Path.Direction.CW); // add "selection" rect; RectF inner = new RectF(left, top, right, bottom); outerPath.addRect(inner, Path.Direction.CW); // set the fill rule so inner area will not be painted outerPath.setFillType(Path.FillType.EVEN_ODD); // set up paints Paint outerPaint = new Paint(); outerPaint.setColor(0x60000000); Paint borderPaint = new Paint(); borderPaint.setARGB(255, 255, 128, 0); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(4); // draw canvas.drawPath(outerPath, outerPaint); canvas.drawRect(inner, borderPaint);
private void drawTriangle(int x, int y, int width, int height, boolean inverted, Paint paint, Canvas canvas){ Point p1 = new Point(x,y); int pointX = x + width/2; int pointY = inverted? y + height : y - height; Point p2 = new Point(pointX,pointY); Point p3 = new Point(x+width,y); Path path = new Path(); path.setFillType(Path.FillType.EVEN_ODD); path.moveTo(p1.x,p1.y); path.lineTo(p2.x,p2.y); path.lineTo(p3.x,p3.y); path.close(); canvas.drawPath(path, paint); }
private Path createStarBySyze(float width, int steps) { float halfWidth = width / 2.0F; float bigRadius = halfWidth; float radius = halfWidth / 2.0F; float degreesPerStep = (float) Math.toRadians(360.0F / (float) steps); float halfDegreesPerStep = degreesPerStep / 2.0F; Path ret = new Path(); ret.setFillType(FillType.EVEN_ODD); float max = (float) (2.0F* Math.PI); ret.moveTo(width, halfWidth); for (double step = 0; step < max; step += degreesPerStep) { ret.lineTo((float)(halfWidth + bigRadius * Math.cos(step)), (float)(halfWidth + bigRadius * Math.sin(step))); ret.lineTo((float)(halfWidth + radius * Math.cos(step + halfDegreesPerStep)), (float)(halfWidth + radius * Math.sin(step + halfDegreesPerStep))); } ret.close(); return ret; }
private void drawCircumscribedTriangle(Canvas canvas, float circleCenterX, float circleCenterY, float radius, Paint paint) { float xOffsetFromCenter = FloatMath.cos((float)Math.PI/6) * radius; float yOffsetFromCenter = FloatMath.sin((float)Math.PI/6) * radius; Path path = new Path(); path.setFillType(Path.FillType.EVEN_ODD); path.moveTo(circleCenterX, circleCenterY - radius); path.lineTo(circleCenterX + xOffsetFromCenter, circleCenterY + yOffsetFromCenter); path.lineTo(circleCenterX - xOffsetFromCenter, circleCenterY + yOffsetFromCenter); path.lineTo(circleCenterX, circleCenterY - radius); path.lineTo(circleCenterX, circleCenterY - radius); canvas.drawPath(path, paint); }
Path path= new Path(); path.setFillType(Path.FillType.EVEN_ODD); path.moveTo(a.x, a.y); // Move to a path.lineTo(center.x, center.y); // Segment from a to center path.lineTo(b.x, b.y); // Segment from center to b path.close(); // Segment from b to a canvas.drawPath(path, paint);
public void onDraw(Canvas c){ Path path = new Path(); path.setFillType(Path.FillType.EVEN_ODD); path.moveTo(insideRectangleOffset, getHeight() - insideRectangleOffset); path.lineTo(getWidth() - insideRectangleOffset, insideRectangleOffset); path.lineTo(getWidth() - insideRectangleOffset, getHeight() - insideRectangleOffset); path.lineTo(insideRectangleOffset, getHeight() - insideRectangleOffset); path.close(); c.drawPath(path, paint); }
private Path getOutlinePath(float w, float h) { Path bodyPath = new Path(); bodyPath.setFillType(Path.FillType.EVEN_ODD); bodyPath.moveTo(w* 0.5f, h); bodyPath.cubicTo(w * 0.4f, h * 0.8f, w * 0.3f, h * 0.7f, w * 0.25f, h * 0.6f); bodyPath.cubicTo(w * 0.2f, h * 0.5f, w * 0.1f, h * 0.5f, 0, h * 0.3f); bodyPath.cubicTo(0, h * 0.25f, w * 0.25f, 0, w * 0.5f, 0); bodyPath.cubicTo(w * 0.75f, 0, w, h * 0.25f, w, h * 0.5f); bodyPath.close(); return bodyPath; }
private void fillArrow(Canvas canvas, float x0, float y0, float x1, float y1) { paint.setStyle(Paint.Style.FILL); float deltaX = x1 - x0; float deltaY = y1 - y0; double distance = Math.sqrt((deltaX * deltaX) + (deltaY * deltaY)); float frac = (float) (1 / (distance / 30)); float point_x_1 = x0 + (float) ((1 - frac) * deltaX + frac * deltaY); float point_y_1 = y0 + (float) ((1 - frac) * deltaY - frac * deltaX); float point_x_2 = x1; float point_y_2 = y1; float point_x_3 = x0 + (float) ((1 - frac) * deltaX - frac * deltaY); float point_y_3 = y0 + (float) ((1 - frac) * deltaY + frac * deltaX); Path path = new Path(); path.setFillType(Path.FillType.EVEN_ODD); path.moveTo(point_x_1, point_y_1); path.lineTo(point_x_2, point_y_2); path.lineTo(point_x_3, point_y_3); path.lineTo(point_x_1, point_y_1); path.lineTo(point_x_1, point_y_1); path.close(); canvas.drawPath(path, paint); }
private void fillArrow(Canvas canvas, float x0, float y0, float x1, float y1) { paint.setStyle(Paint.Style.FILL); float deltaX = x1 - x0; float deltaY = y1 - y0; float frac = (float) 0.1; float point_x_1 = x0 + (float) ((1 - frac) * deltaX + frac * deltaY); float point_y_1 = y0 + (float) ((1 - frac) * deltaY - frac * deltaX); float point_x_2 = x1; float point_y_2 = y1; float point_x_3 = x0 + (float) ((1 - frac) * deltaX - frac * deltaY); float point_y_3 = y0 + (float) ((1 - frac) * deltaY + frac * deltaX); Path path = new Path(); path.setFillType(Path.FillType.EVEN_ODD); path.moveTo(point_x_1, point_y_1); path.lineTo(point_x_2, point_y_2); path.lineTo(point_x_3, point_y_3); path.lineTo(point_x_1, point_y_1); path.lineTo(point_x_1, point_y_1); path.close(); canvas.drawPath(path, paint); }
Path path = new Path(); path.setFillType(FillType.EVEN_ODD); path.moveTo(width/5, height/3); //<----- keep only this call to moveTo() path.lineTo((4*width)/5, (height)/3); path.moveTo((4*width)/5, (height)/3); //<----- remove this call path.lineTo(width/2, (17*height)/30); path.moveTo(width/2, (17*height)/30); //<----- remove this call path.lineTo(width/5, height/3); path.moveTo(width/5, height/3); //<----- remove this call path.close(); canvas.drawPath(path, red); //rest of the code
int height = getMeasuredHeight(); int width = getMeasuredWidth(); Path backpath = new Path(); backpath.moveTo(0, 0); backpath.lineTo(0, width); backpath.lineTo(height, width); backpath.lineTo(height, 0); backpath.setFillType(Path.FillType.EVEN_ODD); for(ArrayList<PointF> arc : drawings) { Iterator<PointF> iter = arc.iterator(); Path tempPath = new Path(); PointF p = iter.next(); tempPath.moveTo(p.x, p.y); while (iter.hasNext()) { PointF l = iter.next(); tempPath.quadTo(p.x, p.y, l.x, l.y); p = l; } tempPath.lineTo(p.x, p.y); backpath.addPath(tempPath); canvas.drawPath(path, mBackgroundPaint); canvas.drawPath(tempPath, paint); }