[gdal-dev] copy raster data in between file formats - Java
Imran Rajjad
rajjad at gmail.com
Tue Jun 12 04:31:44 PDT 2012
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();
for testing purpose, currently only trying on small 256 x 256 image,
the gdalinfo of the source image is as :
Files: test.bmp
Size is 256, 256
Coordinate System is `'
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 256.0)
Upper Right ( 256.0, 0.0)
Lower Right ( 256.0, 256.0)
Center ( 128.0, 128.0)
Band 1 Block=256x1 Type=Byte, ColorInterp=Red
Band 2 Block=256x1 Type=Byte, ColorInterp=Green
Band 3 Block=256x1 Type=Byte, ColorInterp=Blue
regards,
--
I.R
More information about the gdal-dev
mailing list