Skip to content

Commit

Permalink
Hardwire TIFFImageReaderSpi to avoid registering bug (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
jendib committed Nov 7, 2013
1 parent 596dd4d commit 77f0368
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion docs-core/src/main/java/com/sismics/tess4j/ImageIOHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.metadata.IIOMetadata;
Expand All @@ -37,6 +39,7 @@
import org.w3c.dom.NodeList;

import com.sun.media.imageio.plugins.tiff.TIFFImageWriteParam;
import com.sun.media.imageioimpl.plugins.tiff.TIFFImageReaderSpi;
import com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriterSpi;

public class ImageIOHelper {
Expand Down Expand Up @@ -69,8 +72,20 @@ public static ByteBuffer getImageByteBuffer(IIOImage image) throws IOException {
writer.setOutput(ios);
writer.write(streamMetadata, new IIOImage(image.getRenderedImage(), null, null), tiffWriteParam);
writer.dispose();

// Read the writed image
ios.seek(0);
BufferedImage bi = ImageIO.read(ios);
ImageReader reader = new TIFFImageReaderSpi().createReaderInstance();
ImageReadParam param = reader.getDefaultReadParam();
reader.setInput(ios, true, true);
BufferedImage bi;
try {
bi = reader.read(0, param);
} finally {
reader.dispose();
ios.close();
}

return convertImageData(bi);
}

Expand Down

0 comments on commit 77f0368

Please sign in to comment.