java从本地获取图片,并反转图片

public static void main(String[] args) throws InterruptedException, IOException {
	
		File file=new File("zp2.png");
		Image im=ImageIO.read(file);
		int w=im.getWidth(null);
		int h=im.getHeight(null);
		BufferedImage b=new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_INT_RGB);
		 b.getGraphics().drawImage(im.getScaledInstance(w,h, Image.SCALE_SMOOTH),  
	                0, 0, null);  
		 BufferedImage b2=new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_INT_RGB);
		 b2.getGraphics().drawImage(im.getScaledInstance(w,h, Image.SCALE_SMOOTH),  
	                0, 0, null);  
		 for(int x=0;x<h;x++)
			for(int y=0;y<w;y++)
			{
				int rgb=b.getRGB(y, x);
				b2.setRGB(w-1-y, x, rgb);
			}
		ImageIO.write(b2, "png", new File("4.png"));   
	}

  

posted @ 2015-09-06 12:11  Lammy  阅读(2057)  评论(0编辑  收藏  举报