有没有 javax.imageio 的好的替代品?

发布于 2024-07-17 06:37:19 字数 657 浏览 17 评论 0原文

我正在寻找 javax.imageio 包的一个很好的替代品,它可以让我对图像进行简单的旋转、剪切和缩放操作。 例如,我想要

int angle, height, width;
image.rotateRight(angle).scale(height, width);

获得向右旋转角度度并缩小到高度 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);

实际上,该代码甚至没有考虑非方形图像,这将需要我对翻译做更多的魔法)。

I'm looking for a good alternative to the javax.imageio package, that lets me do simple rotating, cutting and scaling operations on images. For example, I would like to do

int angle, height, width;
image.rotateRight(angle).scale(height, width);

in order to obtain an image that is rotated angle degrees to the right and scaled down to height x width pixels.

Using Graphics2D and BufferedImages, I will have to do this, which is neither readable, nor easy to write:

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);

(Actually, that code doesn't even account for non-square images, which will require me to do even more magic with the translating).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

双马尾 2024-07-24 06:37:19

Java Advanced Imaging API 其中包含有用的内容,例如 < a href="http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/RotateDescriptor.html" rel="nofollow noreferrer">RotatorDescriptor。

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

There's the Java Advanced Imaging API which contains useful stuff like a RotatorDescriptor.

But I confess I find your above example pretty readable, so I'm not sure you'll get something more to your liking :-)

请叫√我孤独 2024-07-24 06:37:19

我同意 Brian 的观点:JAI 对你来说是一个非常好的选择。 您可能需要编写一些委托者对象来获取所需的可读代码并使用它而不是 JAI API。

您也可以使用处理(http://processing.org)。 它的API比JAI API更简单。 使用处理后,默认情况下您将获得更好的缩放和旋转操作质量。

I agree with Brian: JAI is very good option for you. You may need to write some delegator object to get such readable code as you need and use it instead of JAI API.

Also you may use Processing (http://processing.org). It's API is simpler than JAI API. And as result of using Processing you'll get better quality for scaling and rotating operations by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文