1 2 3 | import java.awt.image.BufferedImage; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public static BufferedImage combineEllipse(BufferedImage source, BufferedImage other, int x, int y, int ox, int oy, int owidth, int oheight, int cx, int cy){ BufferedImage out = new BufferedImage(source.getWidth(), source.getHeight(), source.getType()); Graphics2D g2d = out.createGraphics(); g2d.drawImage(source, 0 , 0 , null ); g2d.dispose(); Ellipse2D.Float ellipse = new Ellipse2D.Float(ox -= cx, oy -= cy, owidth, oheight); for ( int i1 = x - cx, i2 = ox; i2 < ox + owidth; i1++, i2++){ for ( int j1 = y - cy, j2 = oy; j2 < oy + oheight; j1++, j2++){ if (ellipse.contains(i2, j2) && (( 0 <= i1 && i1 < source.getWidth()) && ( 0 <= j1 && j1 < source.getHeight()))){ out.setRGB(i1, j1, other.getRGB(i2, j2)); } } } return out; } public static BufferedImage combineEllipse(BufferedImage source, BufferedImage other, int x, int y, int ox, int oy, int owidth, int oheight){ return combineEllipse(source, other, x, y, ox, oy, owidth, oheight, 0 , 0 ); } |
修改前
before

以 combineEllipse(source, other, 100, 100, 0, 0, 200, 200) 修改後
edit with combineEllipse(source, other, 100, 100, 0, 0, 200, 200)

以 combineEllipse(source, other, 150, 150, 150, 150, 200, 200, 100, 100) 修改後
edit with combineEllipse(source, other, 150, 150, 150, 150, 200, 200, 100, 100)

沒有留言 :
張貼留言