#include
#include
#include
#include
#include
#include
#include "gdal_priv.h"
#include "gdal.h"
BYTE * imread(const char *filename, int &nbands, int &lWidth, int &lHeight)
{
GDALAllRegister();
GDALDataset *pDataSet = (GDALDataset *)GDALOpen(filename, GA_ReadOnly);
if (!pDataSet)
{
printf("open tif file failed!\n");
return NULL;
}
nbands = pDataSet->GetRasterCount();
lWidth = pDataSet->GetRasterXSize();
lHeight = pDataSet->GetRasterYSize();
BYTE* pData = new BYTE[lWidth*lHeight*nbands];//{x,y}(0),{x,y}(1),...,{x,y}(n)
pDataSet->RasterIO(GF_Read, 0, 0, lWidth, lHeight, pData, lWidth, lHeight, GDT_Byte, nbands, 0, 0, 0, 0);
return pData;
}