I am new to Java and a student of geomatics. I am using IntelliJ. I would like to create a TIFF from BufferedImage. This is my code:
byte[] buffer = new byte[width * height];
ColorSpace cs = ColorSpace.getInstance( ColorSpace.CS_GRAY );
int[] nBits = { 8 };
ColorModel cm = new ComponentColorModel( cs, nBits, false, true,Transparency.OPAQUE, DataBuffer.TYPE_BYTE );
SampleModel sm = cm.createCompatibleSampleModel( width, height );
DataBufferByte db = new DataBufferByte( buffer, width * height );
WritableRaster raster = Raster.createWritableRaster( sm, db, null);
BufferedImage result = new BufferedImage( cm, raster, false , null );
File outputfile = new File( "saved.png" );
ImageIO.write( result, "png", outputfile );
The .png raster is created and works well. But I want to create .TIFF and ImageIO.write without creating TIFF (only png, bmp and jpeg). So I download JAI (Java Advanced Imaging) here: http://download.java.net/media/jai/builds/release/1_1_3/
I upload it to my project and to Maven, but I don’t know how to make tiff just ... I try some fragments that I found on the Internet, but this does not work.
TIFFEncodeParam params = new TIFFEncodeParam();
FileOutputStream os = new FileOutputStream("PingsTiff.tiff");
javax.media.jai.JAI.create("encode", result, os, "TIFF", params);
"TIFFEncodeParam" and "media" are not recognized ... and I'm really a noob when programming.
thanks
source
share