Listing 4. The method named clipToEllipse. |
|---|
private Picture clipToEllipse(Picture pix){
Picture result =
new Picture(pix.getWidth(),pix.getHeight());
result.setAllPixelsToAColor(Color.RED);
//Get the graphics2D object
Graphics2D g2 =
(Graphics2D)(result.getGraphics());
//Create an ellipse for clipping
Ellipse2D.Double ellipse =
new Ellipse2D.Double(28,64,366,275);
//Use the ellipse for clipping
g2.setClip(ellipse);
//Draw the image
g2.drawImage(pix.getImage(),0,0,
pix.getWidth(),
pix.getHeight(),
null);
return result;
}//end clipToEllipse
|