Convert from JPG to TIFF in Android (Java)

1

As the title says, I wonder if someone has converted a bitmap or JPG to TIFF in android.

Thank you in advance. Greetings.

    
asked by Keops 09.11.2016 в 18:21
source

1 answer

1

Good morning, here is an example of how to convert to TIFF, the code I took from this forum and this question by StackOverflow in English

protected boolean saveTiff(String filename, BufferedImage image) {

File tiffFile = new File(filename);
ImageOutputStream ios = null;
ImageWriter writer = null;

try {

// find an appropriate writer
Iterator it = ImageIO.getImageWritersByFormatName("TIF");
if (it.hasNext()) {
writer = (ImageWriter)it.next();
} else {
return false;
}

// setup writer
ios = ImageIO.createImageOutputStream(tiffFile);
writer.setOutput(ios);
TIFFImageWriteParam writeParam = new TIFFImageWriteParam(Locale.ENGLISH);
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
// see writeParam.getCompressionTypes() for available compression type strings
writeParam.setCompressionType("PackBits");

// convert to an IIOImage
IIOImage iioImage = new IIOImage(image, null, null);

// write it!
writer.write(null, iioImage, writeParam);

} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;

}

Now, since the TIFF can save many images, here you have another question from StackOverflow in English on that topic.

    
answered by 09.11.2016 в 20:01