降低java中的图像分辨率
我需要使用Java程序减小图像的大小(不是宽度和高度)。 他们有什么好的 API 可以用于此吗?
我需要将大小从 1MB 减少到大约 50kb - 100 kb。 当然,分辨率会降低,但这并不重要。
I need to reduce the size of image(not the width and height) using Java program.
Is their any good API available for this?
I need to reduce the size from 1MB to about 50kb - 100 kb's.
Of-course the resolution will decrease but that doesn't matter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据这篇博客文章: http://i-proving.com/ 2006/07/06/java-advanced-imaging/ 您可以使用Java 高级成像库 来完成您想要的操作。以下示例代码应该为您提供一个良好的起点。这将调整图像的高度和宽度以及图像质量。一旦图像达到所需的文件大小,您可以在显示图像时将其缩放回所需的像素高度和宽度。
According to this blog post: http://i-proving.com/2006/07/06/java-advanced-imaging/ you can use the Java Advanced Imaging Library to do what you want. The following sample code should provide you a good starting point. This will resize the image, both in height and width, as well as image quality. Once your image is of the desired file size, you can scale it back up to your desired pixel height and width when you display the image.
这是工作代码
这个代码对我来说工作得很好。如果您需要调整图像大小,那么您可以
在此更改 x 和 y 比例
JAI.create("SubsampleAverage", image, xscale,yscale,qualityHints);
This is the working code
This code is Working Great for me. if you need to resize the image then you can
change the x and y scale here
JAI.create("SubsampleAverage", image, xscale,yscale, qualityHints);
您可以使用 JAI 来提高写入 JPEG 的压缩率,而无需进行任何缩放。请参阅 http://java.sun。 com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Encode.doc.html
You can use JAI to increase the compression of a written JPEG without doing any scaling. See http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Encode.doc.html
如果
的实现支持您的图像类型ImageWriteParam
,您可以调整质量,如示例。其他ImageWriteParam
方法,例如getBitRate()
,可以让您优化结果。If your image type is supported by an implementation of
ImageWriteParam
, you can adjust the quality as shown in this example. OtherImageWriteParam
methods, such asgetBitRate()
, may allow you to optimize the result.