0

so I'm trying to rotate an image in Java. It runs for a couple of seconds and when I check the folder while it's running I can see that the image is being manipulated. However, after a few more seconds the image seems to disappear from the folder and I'm flagged with a FileNotFoundException. I've checked with other image rotating questions around here and my code seems similar to theirs so I can't really tell what I'm doing wrong.

If anyone can point it out or send me a link that could help that'd be great. Thanks!

    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. If anyone's curios what I'm trying to rotate, it's basically an image of a letter. The letter has a straight line beneath it that indicates the proper orientation of the letter. That's what the for() loop is for.

blah
  • 101
  • 2
  • 10
  • Possible duplicate of [Rotating Image with AffineTransform](https://stackoverflow.com/questions/20275424/rotating-image-with-affinetransform) – SedJ601 Mar 12 '18 at 19:07
  • I read the post and I don't think it's a duplicate, either that or I'm just stupid (probably stupid but yeah, I don't think it's the same question :\\) – blah Mar 19 '18 at 14:40
  • Seems to me that you can take the ideas from the link to rotate the image. After that you only need to delete the old image and save the new rotated image in its place. – SedJ601 Mar 19 '18 at 14:44
  • oohh, I thought you were implying that we have the same question, but you were pointing out a different way to do it (which is cool btw), ayt thanks. . .also, would you happen to know anything about antlr? (just curious) – blah Mar 19 '18 at 14:53
  • I know nothing about `antlr`. – SedJ601 Mar 19 '18 at 14:55
  • ayt, and thanks again – blah Mar 19 '18 at 14:59

0 Answers0