Reputation:
I have some image constrain code that allows you to output to a MemoryCacheImageOutputStream, but I need to get this back into a BufferedImage, any suggestions?
Upvotes: 1
Views: 838
Reputation: 26796
As MemoryCacheImageOutputStream
implements ImageInputStream
, you could just use it as an input stream for an ImageReader
. So you would end up with something like this (very basic, not tested):
public BufferedImage readImage(MemoryCacheImageOutputStream input) {
ImageInputStream is = input;
ImageReader decoder = ImageIO.getImageReadersByFormatName("JPEG").next();
decoder.setInput(is);
BufferedImage bi = decoder.read(0);
return bi;
}
Upvotes: 2