I just want the user of my website to change the orientation of the submitted photo from horizontal to vertical. Here is my code:
public static final void rotatePhoto(String jpgFilename){ BufferedImage originalImage = null, newImage=null; try{ File file = new File(jpgFilename); originalImage = ImageIO.read(file); System.out.println("Photo.rotatePhoto(" +jpgFilename +") originalImage.getWidth(null)=" +originalImage.getWidth(null) +" originalImage.getHeight(null)=" +originalImage.getHeight(null) ); java.awt.image.AffineTransformOp opRotated = new java.awt.image.AffineTransformOp( java.awt.geom.AffineTransform.getQuadrantRotateInstance(1), null ); newImage = opRotated.createCompatibleDestImage(originalImage, originalImage.getColorModel()); opRotated.filter(originalImage, newImage); }catch (IOException e){ }
The problem is that I get this error, although System.out.println shows the width and height of 640x480
java.awt.image.RasterFormatException: Transformed width (0) is less than or equal to 0. java.awt.image.AffineTransformOp.createCompatibleDestImage(AffineTransformOp.java:447) base.Photo.rotatePhoto(Photo.java:135) base.ProcessContent.handleInput(ProcessContent.java:245) servlets.ProcessServlet.doPost(ProcessServlet.java:74) servlets.ProcessServlet.doGet(ProcessServlet.java:33) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Any ideas or workarounds?
source share