c++下Gdal将16bit的tif图像转8bit
【使用软件及版本】Gdal4.x(含proj等),vs2019
打包完的,到手即用。
头文件(仅罗列关键文件,其他基础自行添加)
#include "gdal_priv.h"
#include "gdal.h"
#include<algorithm>
class imageprocessing
{
public:
int stretch_percent_16to8(const char* inFilename, const char* dstFilename);
};
可有可无文件,具体功能不太清楚
typedef unsigned __int16 uint16_t;
typedef unsigned unsigned char uint8_t;
cpp文件
int imageprocessing::stretch_percent_16to8(const char* inFilename, const char* dstFilename)
{
GDALAllRegister();
//为了支持中文路径
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO");
int src_height = 0;
int src_width = 0;
GDALDataset* poIn = (GDALDataset*)GDALOpen(inFilename, GA_ReadOnly); //打开影像
//获取影像大小
src_width = poIn->GetRasterXSize();
src_height = poIn->GetRasterYSize();
//获取影像波段数
int InBands = poIn->GetRasterCount();
//获取影像格式
GDALDataType eDataType = poIn->GetRasterBand(1)->GetRasterDataType();
//定义存储影像的空间参考数组
double adfInGeoTransform[6] = {
0 };
const char* pszWKT = NULL;
//获取影像空间参考
poIn->GetGeoTransform(adfInGeoTransform);
pszWKT = poIn->GetProjectionRef();
//创建文件
GDALDriver* poDriver = (GDALDriver*)GDALGetDriverByName("GTiff")<

最低0.47元/天 解锁文章
5250





