Pass in the correct file type to the BufferedImage
and it should work.
PNG
BufferedImage originalImage = JAI.create("png", pb).getAsBufferedImage();
GIF
BufferedImage originalImage = JAI.create("gif", pb).getAsBufferedImage();
And have a look at this answer to get the file extensions.