You should make sure about the actual representation of the raster image, whether it represents the pixel as floats as you have used float arrays in the code. The last 2 parameters are used to define the byte offset of the pixels and lines in the image ( for more info see the RasterIO<http://www.gdal.org/classGDALRasterBand.html#5497e8d29e743ee9177202cb3f61c3c7>documentation).
Further C# related samples can be found here: http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/csharp/apps/GDALRead.cs http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/csharp/apps/GDALReadDirect.cs Best regards, Tamas 2011/8/31 hitweiran <hitwei...@sina.com> > I want to read a multiband image(in format of .img) by using method > ReadRaster, however, I encount some problems. I just can't understand why > the data loaded to memory is wrong? > the code is like this > > OSGeo.GDAL.Dataset dataSet = > OSGeo.GDAL.Gdal.Open(@"G:\building.img",OSGeo.GDAL.Access.GA_ReadOnly); > int width = dataSet.RasterXSize; > int height = dataSet.RasterYSize; > int Band_Numbers = dataSet.RasterCount; > float [] buffer_first = new float [width * height]; > OSGeo.GDAL.Band One_Band = dataSet.GetRasterBand(1); > One_Band.ReadRaster(0, 0, width, height,buffer_first, width, height, 0,0); > > However, the output is wrong! > I watch the variable "buffer_first" in watch window, and discoverse that > the > data is quite terrible-some data is such as 2.818478E+21,5.065476E+32, or > -6.131138E-11 and so on; > So I suspect my datatype is mismatch to data in img file, or the last two > arguments in ReadRaster is mistake, because I don't know the meaning of > last > two parameters. > Thanks a lot for your answer! > > -- > View this message in context: > http://osgeo-org.1803224.n2.nabble.com/The-problem-when-using-ReadRaster-C-method-tp6745826p6745826.html > Sent from the GDAL - Dev mailing list archive at Nabble.com. > _______________________________________________ > gdal-dev mailing list > gdal-dev@lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/gdal-dev >
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev