[gdal-dev] copy raster data in between file formats - Java

Even Rouault even.rouault at mines-paris.org
Tue Jun 12 11:14:31 PDT 2012


Le mardi 12 juin 2012 13:31:44, Imran Rajjad a écrit :
> Dear List,
> 
> Have been trying to write raster from one file format e.g. BMP into a
> tiff file which will eventually become a BIGTiff. The current output
> is a grey image whereas the output should be RGB. The GeoTiFF is not
> accepting bands for some reasons, To write a multiband geoTiff do we
> require to add each band separately or is there something missing in
> the below code snippet?
> 
>                 gdal.AllRegister();
> 		Driver driver = gdal.GetDriverByName("GTiff");
> 		Dataset dst = driver.Create("d:\\test.tif", 256,
> 256,3,gdalconst.GDT_Byte); Dataset src = gdal.Open("d:\\test.bmp");
> 
> 
> 		byte[] outputPixels = new byte[src.GetRasterXSize() *
> src.GetRasterYSize() * src.getRasterCount()*Integer.SIZE];
> 		src.ReadRaster(0, 0, src.getRasterXSize(), src.getRasterYSize(),
> src.getRasterXSize(), src.getRasterYSize(), gdalconst.GDT_Byte,
> outputPixels, null, 0);
> 		dst.WriteRaster(0, 0, src.getRasterXSize(), src.getRasterYSize(),
> src.getRasterXSize(), src.getRasterYSize(), gdalconst.GDT_Byte,
> outputPixels, null, 0);
> 		dst.FlushCache();
> 		dst.delete();
> 		src.delete();
> 

I've just tested the above snippet with a 256x256 image and it works as 
expected. Not sure why you have a problem. Do you use a recent GDAL version, 
let's say 1.9 ?


More information about the gdal-dev mailing list