java 2d - How to copy a region of an image enclosed by cubic curves -
i have java program works similar bezier tool in inkscape. purpose of program allow user use curves draw path around object (like head of person) , extract (copy) pixels inside enclosed curves. in attached picture, can see there 3 blue curves form enclosed area. i'd know how copy area enclosed these 3 curves?
the code use draw curves (i omit red tangent lines , red control points simplicity):
cubiccurve1 = new cubiccurve2d.double( p1.x, p1.y, p1control1.x, p1control1.y, p2control1.x, p2control1.y, p2.x, p2.y); cubiccurve2 = new cubiccurve2d.double( p2.x, p2.y, p2control2.x, p2control2.y, p3control1.x, p3control1.y, p3.x, p3.y); cubiccurve3 = new cubiccurve2d.double( p3.x, p3.y, p3control2.x, p3control2.y, p1control1.x, p1control1.y, p1.x, p1.y); g2d.setpaint(color.blue); g2d.draw(cubiccurve1); g2d.draw(cubiccurve2); g2d.draw(cubiccurve3);
here's how solved problem:
generalpath shape = new generalpath(); shape.moveto(cubiccurve1.x1, cubiccurve1.y1); shape.curveto(cubiccurve1.ctrlx1, cubiccurve1.ctrly1, cubiccurve1.ctrlx2, cubiccurve1.ctrly2, cubiccurve1.x2, cubiccurve1.y2); shape.curveto(cubiccurve2.ctrlx1, cubiccurve2.ctrly1, cubiccurve2.ctrlx2, cubiccurve2.ctrly2, cubiccurve2.x2, cubiccurve2.y2); shape.curveto(cubiccurve3.ctrlx1, cubiccurve3.ctrly1, cubiccurve3.ctrlx2, cubiccurve3.ctrly2, cubiccurve1.x1, cubiccurve1.y1); g2d.draw(shape); g2d.setclip(shape); // draw image g2d.drawimage(image, 0, 0, this);