从Java中的非常大的图像文件中读取区域 [英] Read region from very large image file in Java
本文介绍了从Java中的非常大的图像文件中读取区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一个Java库可以读取超大图像(例如JPEG)文件的区域(> 10,000 x 10,000像素),而不会将整个图像保留在内存中。
Is there a Java library that can read regions of very large image (e.g. JPEG) files (> 10,000 x 10,000 pixels) without keeping the whole image in memory.
或者,哪个Java库能够以最小的开销处理非常大的图像文件。
Or alternatively, which Java library is capable of handling very large image files with a minimum of overhead.
推荐答案
标准ImageIO允许您读取(大)图像的区域而不首先将整个图像读入存储器。
Standard ImageIO allows you to read regions of (large) images without reading the entire image into memory first.
Rectangle sourceRegion = new Rectangle(x, y, w, h); // The region you want to extract
ImageInputStream stream = ImageIO.createImageInputStream(input); // File or input stream
Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
if (readers.hasNext()) {
ImageReader reader = readers.next();
reader.setInput(stream);
ImageReadParam param = reader.getDefaultReadParam();
param.setSourceRegion(sourceRegion); // Set region
BufferedImage image = reader.read(0, param); // Will read only the region specified
}
这篇关于从Java中的非常大的图像文件中读取区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文