[Gdal-dev] Digging Java JNI bindings
Norman Barker
nbarker at ittvis.com
Mon Oct 30 05:59:07 EST 2006
-----Original Message-----
From: gdal-dev-bounces at lists.maptools.org
[mailto:gdal-dev-bounces at lists.maptools.org] On Behalf Of Simone
Giannecchini
Sent: 28 October 2006 02:32
To: gdal-dev at lists.maptools.org
Subject: [Gdal-dev] Digging Java JNI bindings
Hi list,
I am playing with the GDAL SWIG bindings for Java in order to continue
the work that Daniele Romagnoli carried out for the Summer Of Code
program. So far we have achieved to built ImageIO plugins to read
ECW, JPEG2K and HDF dataset. I am starting to play around with
creating datasets but I am a bit stuck. Before starting to look at
extending the actual Java bindings to best work in a tile(block)
oriented way I wanted to play around a bit with what it is availaible
right now. I am trying with the following code in order to convert a
jpeg image into a tiff image. I get no error but the output tiff
appears to be empty.
final File outFile = new File("c:/out.tiff");
final BufferedImage im = ImageIO.read(new
File("c:/2.jpg"));
outFile.createNewFile();
Driver jp2kDriver = gdal.GetDriverByName("GTiff");
Dataset ds =
jp2kDriver.Create(outFile.getAbsolutePath(),
im.getWidth(), im.getHeight(), 3,
gdalconstConstants.GDT_Byte,
null);
RenderedOp b0 = BandSelectDescriptor.create(im, new
int[] { 0 }, null);
RenderedOp b1 = BandSelectDescriptor.create(im, new
int[] { 1 }, null);
RenderedOp b2 = BandSelectDescriptor.create(im, new
int[] { 2 }, null);
ds.GetRasterBand(1).WriteRaster_Direct(
0,
0,
im.getWidth(),
im.getHeight(),
0,
0,
gdalconstConstants.GDT_Byte,
ByteBuffer.wrap(((DataBufferByte)
b0.getAsBufferedImage()
.getData().getDataBuffer()).getData(0)));
ds.GetRasterBand(2).WriteRaster_Direct(
0,
0,
im.getWidth(),
im.getHeight(),
0,
0,
gdalconstConstants.GDT_Byte,
ByteBuffer.wrap(((DataBufferByte)
b1.getAsBufferedImage()
.getData().getDataBuffer()).getData(0)));
ds.GetRasterBand(2).WriteRaster_Direct(
0,
0,
im.getWidth(),
im.getHeight(),
0,
0,
gdalconstConstants.GDT_Byte,
ByteBuffer.wrap(((DataBufferByte)
b2.getAsBufferedImage()
.getData().getDataBuffer()).getData(0)));
I am sure I am missing something, any hint is greatly appreciated!
Thx,
Simone.
--
Simone,
If by the output tiff being empty, you mean you only get the 8 byte tiff
header then you need to add
ds.FlushCache();
ds.delete();
to the end your routine this forces the file to be created, this could
be added to a finalizer of one of your base classes if you wanted to
hide it, I have just tried it with your code and it creates the whole
file.
Norman
More information about the Gdal-dev
mailing list