资源简介
基于对话框格式,试验运行能打开500M.TIF图像,.TIFF色调比较白,不怎么清楚,有待改善,需要安装GDAL,只要把VS2010(本人所用),工程名右键属性打开,将其包含目录,和库目录分别换成你安装的gdal文件中的include和bin路径,最后再在链接器的输入栏第一个选项键入:gdal_i.lib,运行即可
代码片段和文件信息
#include “cximagedlg.h“
#include
#include
#include
#include “gdal_priv.h“
CXImageDlg::CXImageDlg(QWidget *parent Qt::WFlags flags)
: QDialog(parent flags)
{
ui.setupUi(this);//setupUi(this);
Qobject::connect(ui.buttonBox SIGNAL(clicked()) this SLOT(OnOK()));
Qobject::connect(ui.buttonBox2 SIGNAL(clicked()) this SLOT(close()));
Qobject::connect(ui.pushButtonInput SIGNAL(clicked()) this SLOT(LoadInputRaster()));
Qobject::connect(ui.pushButtonApply SIGNAL(clicked()) this SLOT(soltApply()));
ui.labelView->clear();
m_pDataset = NULL;
}
CXImageDlg::~CXImageDlg()
{
if(m_pDataset != NULL)
{
GDALClose((GDALDatasetH) m_pDataset);
m_pDataset = NULL;
}
}
bool CXImageDlg::ShowRasterFile()
{
GDALAllRegister();
m_pDataset = (GDALDataset*)GDALOpen(m_strInputRaster.c_str() GA_ReadOnly);
if (m_pDataset == NULL)
{
QMessageBox::information(thistr(“提示“) tr(“指定的文件不能打开!“));
return false;
}
//设置投影坐标范围
int dataWidth = m_pDataset->GetRasterXSize();
int dataHeight = m_pDataset->GetRasterYSize();
double padfTransform[6] = {0.0};
m_pDataset->GetGeoTransform(padfTransform);
//设置行列号范围
ui.spinStartCol->setRange(0 dataWidth-1);
ui.spinStartRow->setRange(0 dataHeight-1);
ui.spinEndCol->setRange(0 dataWidth-1);
ui.spinEndRow->setRange(0 dataHeight-1);
ui.spinStartCol->setValue(0);
ui.spinStartRow->setValue(0);
ui.spinEndCol->setValue(dataWidth-1);
ui.spinEndRow->setValue(dataHeight-1);
ShowRaster();
//return 0;
}
void CXImageDlg::LoadInputRaster()
{
QFileDialog::Options options;
QString selectedFilter;
QString fileName = QFileDialog::getOpenFileName(this
tr(“打开原始图像“)
“.“
tr(“所有文件(*.*);;Erdas Image (*.img);;PCIDSK (*.pix);;GTiff (*.tif *.tiff);;ENVI (*.*)“)
&selectedFilter
options);
if (!fileName.isEmpty())
{
if(m_pDataset != NULL)
{
GDALClose((GDALDatasetH) m_pDataset);
m_pDataset = NULL;
}
ui.lineInput->setText(fileName);
m_strInputRaster = QFile::encodeName( fileName ).constData();
if(!ShowRasterFile())
{
ui.lineInput->setText(““);
m_strInputRaster = ““;
}
}
}
void CXImageDlg::ShowRaster()
{
int iStartCol = ui.spinStartCol->value();
int iStartRow = ui.spinStartRow->value();
int dataWidth = ui.spinEndCol->value() - iStartCol;
int dataHeight = ui.spinEndRow->value() - iStartRow;
int dataBands = m_pDataset->GetRasterCount();
int band_list[3] = {123};
m_dScale = dataHeight > dataWidth ? dataHeight : dataWidth;
int iViewHeight = 541;
m_dScale = iViewHeight/m_dScale;
int iSize = GDALGetDataTypeSize(GDT_Byte) / 8;
int iScaleWidth = static_cast(dataWidth*m_dScale+0.5);
int iScaleHeight = static_cast(dataHeight*m_dScale+0.5);
iScaleWidth = (iScaleWidth*8+31)/32*4;
unsigned char* pBuffer = new unsigned char[iScaleWidth*iScaleHeight*dataBands];
CPLErr err = m_pDataset->RasterIO(GF
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3794 2014-03-05 18:36 CXImageDlg\CXImageDlg\cximagedlg.cpp
文件 916 2014-03-02 21:39 CXImageDlg\CXImageDlg\cximagedlg.h
文件 70 2014-03-02 21:11 CXImageDlg\CXImageDlg\cximagedlg.qrc
文件 4382 2014-03-05 18:32 CXImageDlg\CXImageDlg\cximagedlg.ui
文件 10977 2014-03-02 21:43 CXImageDlg\CXImageDlg\CXImageDlg.vcxproj
文件 2699 2014-03-02 21:11 CXImageDlg\CXImageDlg\CXImageDlg.vcxproj.filters
文件 575 2014-03-02 21:39 CXImageDlg\CXImageDlg\CXImageDlg.vcxproj.user
文件 3994 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\cl.command.1.tlog
文件 94702 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\CL.read.1.tlog
文件 1890 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\CL.write.1.tlog
文件 1552 2014-03-05 18:32 CXImageDlg\CXImageDlg\Debug\custombuild.command.1.tlog
文件 420 2014-03-05 18:32 CXImageDlg\CXImageDlg\Debug\custombuild.read.1.tlog
文件 758 2014-03-05 18:32 CXImageDlg\CXImageDlg\Debug\custombuild.write.1.tlog
文件 608 2014-03-02 21:43 CXImageDlg\CXImageDlg\Debug\CXImageDlg.Build.CppClean.log
文件 381 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\CXImageDlg.exe.intermediate.manifest
文件 53 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\CXImageDlg.lastbuildstate
文件 2752 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\CXImageDlg.log
文件 688806 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\cximagedlg.obj
文件 1370 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\CXImageDlg.write.1.tlog
文件 1886 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\li
文件 3426 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\li
文件 960 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\li
文件 89756 2014-03-05 18:32 CXImageDlg\CXImageDlg\Debug\main.obj
文件 68717 2014-03-05 18:32 CXImageDlg\CXImageDlg\Debug\moc_cximagedlg.obj
文件 458 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\mt.command.1.tlog
文件 734 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\mt.read.1.tlog
文件 274 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\mt.write.1.tlog
文件 16025 2014-03-02 21:57 CXImageDlg\CXImageDlg\Debug\qrc_cximagedlg.obj
文件 1159168 2014-03-05 18:36 CXImageDlg\CXImageDlg\Debug\vc100.pdb
文件 3070 2014-03-02 21:43 CXImageDlg\CXImageDlg\GeneratedFiles\Debug\moc_cximagedlg.cpp
............此处省略27个文件信息
评论
共有 条评论