c++下Gdal将16bit的tif图像转8bit

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")<
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值