0
点赞
收藏
分享

微信扫一扫

基于GDAL库读取tiff文件的C++代码

兮城 2022-06-09 阅读 55
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>

#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;
}

 


举报

相关推荐

0 条评论