use*_*275 5 java image image-resizing
寻找像 djpeg 这样的东西,它使用 O(1) RAM 通过子采样调整大小,但在 java 中并且能够处理 jpg、png、gif、bmp 等。也许一些实现已经存在。如何调整流中图像的大小(使用最少的 RAM)?
The FileImageInputStream doesn't know anything about specific image formats, it's just convenience for reading ints, shorts, bytes, byte arrays, etc, from a file-backed input. File format support is handled by the various ImageReader implementations.
The short answer to your question is: You can't really resize an image without loading it.
From the description of djpeg:
djpeg decompresses the named JPEG file [...]
(Emphasis is mine)
However, you can subsample images, wich is really fast (for most formats), and will uses less memory. Have a look at the ImageReadParam.setSourceSubSampling method and the ImageReader.read(int, ImageReadParam) method. This will create a resized image, quite similar to the "nearest neighbour" or "point sampling" algorithms (ie. the results won't necessary look good).
It's possible to combine subsampling first, with better quality resizing afterwards, to save memory, and possibly get acceptable results. It all depends on what quality you expect/need.
如果您真的,真的想调整图像大小而不将它们加载到堆内存中(也许您的图像很大),我已经编写了一些使用内存映射文件的类,您可以查看它们,但它们非常缓慢。
| 归档时间: |
|
| 查看次数: |
2269 次 |
| 最近记录: |