Swing之图片水平翻转、垂直翻转、180度旋转

 淘宝精品导航:http://www.nitaomei.com

AffineTransform 类表示 2D 仿射变换,它执行从 2D 坐标到其他 2D 坐标的线性映射,保留了线的“直线性”和“平行性”。可以使用一系列平移、缩放、翻转、旋转和剪切来构造仿射变换。

 

 

import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; import java.io.FileInputStream; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTabbedPane; /** * 使图片水平翻转、垂直翻转、旋转180度 * @author Administrator */ public class TestPicture { public static void main(String[] args) throws IOException { BufferedImage sourceImage = ImageIO.read(new FileInputStream("title4.gif")); BufferedImage dstImage = null; AffineTransform transform = new AffineTransform(-1,0,0,1,sourceImage.getWidth()-1,0);//水平翻转 // AffineTransform transform = new AffineTransform(1,0,0,-1,0,sourceImage.getHeight()-1);//垂直翻转 // AffineTransform transform = new AffineTransform(-1,0,0,-1,sourceImage.getWidth()-1,sourceImage.getHeight()-1);//旋转180度 AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); dstImage = op.filter(sourceImage, null); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.add("Source Transform", new JLabel(new ImageIcon(sourceImage))); tabbedPane.add("Affine Transform", new JLabel(new ImageIcon(dstImage))); JFrame jframe = new JFrame(); jframe.setSize(800, 600); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.getContentPane().add(tabbedPane); jframe.setVisible(true); } }

 

淘宝精品导航:http://tb99.web-59.com

 

 

你可能感兴趣的:(swing,import,null,string,class)