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?
+2
A:
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;
}
MicSim
2009-02-20 23:24:34