The code below is supposed to convert an image to its Base64 string. It works but for TIF, only the first "page" is converted and the succeeding pages/parts are missing.
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedBytes = null;
File file = new File("newtif.tif");
try {
FileOutputStream fop;
decodedBytes = new BASE64Decoder().decodeBuffer(imageString);
fop = new FileOutputStream(file);
fop.write(decodedBytes);
fop.flush();
fop.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I got the imageString
from an actual multipaged-TIF file and converted it to Base64 using:
BufferedImage image = ImageIO.read(new File(fileLocation));
BufferedImage newImg;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(image, "tif", bos);
byte[] imageBytes = bos.toByteArray();
BASE64Encoder encoder = new BASE64Encoder();
imageString = encoder.encode(imageBytes);
Thank you in advance for your help!