[gdal-dev] Quick question regarding image translation in Java (I think)

Mike O'Malley mike.omalley at nextcentury.com
Thu Jul 28 14:33:46 EDT 2011


Hi,

   Hopefully this is a quick one, I think the answer's so obvious I'm
missing it.  I'm trying to use GDAL to create a TIFF copy of a NITF
file.  I've downloaded and compiled 1.8.1 (under Windows) and used
gdal_translate from the command line to create the copy.  I can view the
new file  from IrfanView and everything looks good.

   When I try to do this programmatically from Java, however, things
break down.  I'm using the Java bindings from 1.7 in case that's an
issue; I've tried a number of things, but haven't recompiled the
bindings yet.  My code is:

 

                  Dataset ds=gdal.Open(datasetFilename,
gdalconstConstants.GA_ReadOnly);

 

                  if (ds == null) {

                        System.out.println("GDALOpen failed - " +
gdal.GetLastErrorNo());

                        System.out.println(gdal.GetLastErrorMsg());

                        gdal.GDALDestroyDriverManager();

                        System.exit(1);

                  }

                  

                  System.out.println("Image has "+ds.getRasterCount()+"
bands");

 

                  Driver driv=gdal.GetDriverByName(saveFormat);

                  driv.CreateCopy(outFilename+"."+saveFormat,ds);

            

  Which looks about as basic as it gets.  The file is created, but it's
slightly shorter than gdal_translate's version of the copy and contains
one color as opposed to the original count of 256 colors.  The histogram
of the new image is completely flat.  Both images are single-band,
though the gdal_translate copy has 8BPP and the new one has 24BPP.  The
dimensions remain unchanged and it's a valid TIFF file, just with bad
pixel data.

   This occurs with most of the NITFs in my set.  The NITFs are viewable
using FWTools and look good; the TIFFs created by gdal_translate match
them.  It's just my Java code that's producing blank images.

 

   Am I missing something obvious?

 

    Thanks,

          Mike

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110728/59413756/attachment.html


More information about the gdal-dev mailing list