那里有javax.imageio的好替代品吗?

Jor*_*orn 2 java javax.imageio

我正在寻找javax.imageio包的一个很好的替代品,它允许我对图像进行简单的旋转,切割和缩放操作.例如,我想做

int angle, height, width;
image.rotateRight(angle).scale(height, width);
Run Code Online (Sandbox Code Playgroud)

为了获得向右旋转角度并向下缩放到高度 x 宽度像素的图像.

使用Graphics2D和BufferedImages,我将不得不这样做,这既不易读也不易写:

BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = result.createGraphics();
graphics.translate(height/2, width/2);
graphics.rotate(angle);
graphics.translate(-width/2, -height/2);
graphics.drawImage(image, 0, 0, width, height, null);
Run Code Online (Sandbox Code Playgroud)

(实际上,该代码甚至不能解释非方形图像,这将要求我在翻译时做更多的魔术).

Bri*_*new 5

还有的Java高级图像API包含了像一个有用的东西RotatorDescriptor.

但我承认我发现你上面的例子很可读,所以我不确定你会得到更多你喜欢的东西:-)