You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2021/04/27 17:12:45 UTC
svn commit: r1889243 -
/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ImageUtil.java
Author: tilman
Date: Tue Apr 27 17:12:45 2021
New Revision: 1889243
URL: http://svn.apache.org/viewvc?rev=1889243&view=rev
Log:
PDFBOX-2941: check rotation input value; keep image type; improve java doc; support some negative values; use int instead of double
Modified:
pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ImageUtil.java
Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ImageUtil.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ImageUtil.java?rev=1889243&r1=1889242&r2=1889243&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ImageUtil.java (original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/ImageUtil.java Tue Apr 27 17:12:45 2021
@@ -36,31 +36,34 @@ public final class ImageUtil
* @param image The image to rotate.
* @param rotation The rotation in degrees.
* @return The rotated image.
+ * @throws IllegalArgumentException if the angle isn't a multiple of 90°.
*/
public static BufferedImage getRotatedImage(BufferedImage image, int rotation)
{
int width = image.getWidth();
int height = image.getHeight();
- double x = 0;
- double y = 0;
+ int x = 0;
+ int y = 0;
BufferedImage rotatedImage;
- switch (rotation % 360)
+ switch ((rotation + 360) % 360)
{
+ case 0:
+ return image;
case 90:
x = height;
- rotatedImage = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB);
+ rotatedImage = new BufferedImage(height, width, image.getType());
break;
case 270:
y = width;
- rotatedImage = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB);
+ rotatedImage = new BufferedImage(height, width, image.getType());
break;
case 180:
x = width;
y = height;
- rotatedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ rotatedImage = new BufferedImage(width, height, image.getType());
break;
default:
- return image;
+ throw new IllegalArgumentException("Only multiple of 90° are supported");
}
Graphics2D g = (Graphics2D) rotatedImage.getGraphics();
g.translate(x, y);