测试环境:
vs2017/vs2019/vs2022
GDAL>=2.31均测试通过
代码功能:
简单读取图片宽和高
代码:
#include "gdal_priv.h"
#include<iostream>
using namespace std;
int main()
{
const char* pszFile;
GDALAllRegister();
pszFile = "D:\\test.jpg";
GDALDataset* poDataset = (GDALDataset*)GDALOpen(pszFile, GA_ReadOnly);
GDALRasterBand* poBand = poDataset->GetRasterBand(1);
int xsize = poBand->GetXSize();
int ysize = poBand->GetYSize();
cout << xsize << endl;
cout << ysize << endl;
getchar();
return 0;
}