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)
(实际上,该代码甚至不能解释非方形图像,这将要求我在翻译时做更多的魔术).
| 归档时间: |
|
| 查看次数: |
2066 次 |
| 最近记录: |