用GDAL的读取函数:
GDALDataset::RasterIO | ( | GDALRWFlag | eRWFlag, | |
int | nXOff, | |||
int | nYOff, | |||
int | nXSize, | |||
int | nYSize, | |||
void * | pData, | |||
int | nBufXSize, | |||
int | nBufYSize, | |||
GDALDataType | eBufType, | |||
int | nBandCount, | |||
int * | panBandMap, | |||
int | nPixelSpace, | |||
int | nLineSpace, | |||
int | nBandSpace | |||
) |
测试代码如下:
int main()
{
char* inputFileName="C:\\TestData.img";
GDALAllRegister(); //利用GDAL读取图片,先要进行注册
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8","NO"); //设置支持中文
//准备读取图片
GDALDataset *ReadDataSet=(GDALDataset*)GDALOpen(inputFileName,GA_ReadOnly);
int width=ReadDataSet->GetRasterXSize();
int height=ReadDataSet->GetRasterYSize();
int bandsCount=ReadDataSet->GetRasterCount();
//分配数据内存
float* data=new float[width*height*bandsCount];
ReadDataSet->RasterIO(GF_Read,0,0,width,height,data,width,height,GDT_Float32,bandsCount,NULL,
sizeof(float)*bandsCount,sizeof(float)*bandsCount*width,sizeof(float)); //得到的data数据就是按BIP方式排列的
return 0;
}