我是靠谱客的博主 繁荣饼干,最近开发中收集的这篇文章主要介绍java thumbnails 内存,Java图像缩放,而无需将整个图像加载到内存中,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

We have some very large jpgs which are used when print on A0 printers.

The problem is that we need to convert this large image down to a thumbnail for use in a few java UIs.

Is there any way to convert the image (with Java) without loading the whole image into memory? Currently we get out of memory exceptions when we try to load the images.

Is there anything in the standard code or is my best bet to use jmagick? A pure java implementation would be best for our deployment.

Thanks

解决方案

I managed to get it working and the full code is as follows.

The call to reader.setInput(iis, true, true); is the magic which I was missing from the previous post.

FileInputStream fin = new FileInputStream(source);

ImageInputStream iis = ImageIO.createImageInputStream(fin);

Iterator iter = ImageIO.getImageReaders(iis);

if (!iter.hasNext()) {

return;

}

ImageReader reader = (ImageReader) iter.next();

ImageReadParam params = reader.getDefaultReadParam();

reader.setInput(iis, true, true);

params.setSourceSubsampling(width, height, 0, 0);

BufferedImage img = reader.read(0, params);

ImageIO.write(img, "JPG", destination);

最后

以上就是繁荣饼干为你收集整理的java thumbnails 内存,Java图像缩放,而无需将整个图像加载到内存中的全部内容,希望文章能够帮你解决java thumbnails 内存,Java图像缩放,而无需将整个图像加载到内存中所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(92)

评论列表共有 0 条评论

立即
投稿
返回
顶部