在Java中旋转图像,从文件夹中删除图像并标记FileNotFoundException

时间:2018-03-12 18:32:37

标签: java rotation affinetransform

所以我试图用Java旋转图像。它会运行几秒钟,当我在文件夹运行时检查它时,我可以看到图像正在被操纵。但是,再过几秒钟后,图像似乎从文件夹中消失,我被标记为FileNotFoundException。我已经检查了周围的其他图像旋转问题,我的代码看起来与他们的相似,所以我无法真正说出我做错了什么。

如果有人可以指出或向我发送一个可以帮助我做得很好的链接。谢谢!

    public static void rotate(String path){
        try{
            File input = new File(path);
            BufferedImage image = ImageIO.read(input);
            BufferedImage image2;
            int x, ave;

            do{
                for(x = ave = 0; x < image.getWidth() && ave == 0; x++){
                    Color c = new Color(image.getRGB(x, image.getHeight()-1));
                    ave = (c.getBlue() + c.getGreen() + c.getRed())/3;
                }

                if(x < image.getWidth()){
                    AffineTransform t = new AffineTransform();
                    t.rotate(Math.toRadians(1), image.getWidth(), image.getHeight());
                    AffineTransformOp o = new AffineTransformOp(t, AffineTransformOp.TYPE_BILINEAR);
                    image2 = o.filter(image, null);
                    ImageIO.write(image2, "png", new File("C:/Users/Table/Desktop/ALPHABET/A3.png"));
                }
            }while(x < image.getWidth());

        }catch(IOException e){}
    }

P.S。如果我想要旋转任何人的好奇心,那么它基本上就是一封信的形象。这封信下方有一条直线,表示信件的正确方向。这就是for()循环的用途。

0 个答案:

没有答案
相关问题