[Gdal-dev] Digging Java JNI bindings
Simone Giannecchini
simboss1 at gmail.com
Fri Oct 27 21:32:06 EDT 2006
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.
--
-------------------------------------------------------
Eng. Simone Giannecchini
President /CEO GeoSolutions
http://www.geo-solutions.it
-------------------------------------------------------
More information about the Gdal-dev
mailing list