2017-06-14 39 views
0

所以,我有几行代码:如何做一个对称 - 图形Java

BufferedImage bufferedImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); 
    Graphics g = bufferedImage.getGraphics(); 
    g.setColor(Color.cyan); 
    g.fillRect(0, 0, 10, 10); 

(在现实中我得出这个图片上的不同shappes ..)

但怎么到(垂直)对称的图像?有没有办法做到这一点?或者我必须代码整个代码...

预先感谢您

+0

你所用图像的symetry意思?你期望什么,到目前为止你尝试过什么? – AxelH

回答

3

https://examples.javacodegeeks.com/desktop-java/awt/image/flipping-a-buffered-image/

// Flip the image vertically 
AffineTransform tx = AffineTransform.getScaleInstance(1, -1); 
tx.translate(0, -image.getHeight(null)); 
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); 
image = op.filter(image, null); 


// Flip the image horizontally 
tx = AffineTransform.getScaleInstance(-1, 1); 
tx.translate(-image.getWidth(null), 0); 
op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); 
image = op.filter(image, null); 

// Flip the image vertically and horizontally; equivalent to rotating the image 180 degrees 
tx = AffineTransform.getScaleInstance(-1, -1); 
tx.translate(-image.getWidth(null), -image.getHeight(null)); 
op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); 
image = op.filter(image, null); 
+3

OP无法执行相同的搜索太遗憾了:P – MadProgrammer