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")); }
时间: 2024-10-15 10:56:42