logo资料库

gdal库读取影像和建立金字塔代码的代码.doc

第1页 / 共29页
第2页 / 共29页
第3页 / 共29页
第4页 / 共29页
第5页 / 共29页
第6页 / 共29页
第7页 / 共29页
第8页 / 共29页
资料共29页,剩余部分请下载后查看
第一段是用 GDAL 读取数据,并转化为位图。 我处理的都是灰度图。所以对于 8 位的位图,GDAL 读取数据信息虽然是调色板序号,但序 号就是其灰度值。 (对于 8 位彩色图自然不是) 其中 str 是打开路径,对于波段为 1 的图像,按照灰度图读取。对于波段》=3 的图像,读 取其中 3 个波段进行灰度化。 C/C++ code bool CPicMatchDoc::CreatImage(int LorR, CString str) { GDALDataset *poDataset; //数据集 GDALAllRegister(); 对象指针 册驱动 //注 USES_CONVERSION; // 在前面加上这句 char *pz =T2A(str); poDataset = (GDALDataset *) GDALOpen(pz, GA_ReadOnly);
if (poDataset == NULL) /* 检查是否正常打开文件*/ { if(LorR==0) AfxMessageBox(_T("打开左片影像文件失败! "),0,0); else AfxMessageBox(_T("打开右片影像文件失败! "),0,0); return 0; } BeginWaitCursor(); //输入图像的信息 int nBands = poDataset->GetRasterCount(); GDALRasterBand ** poBand; //各波段信息指针
poBand = new GDALRasterBand *[nBands]; if (poBand == NULL) { AfxMessageBox(_T("创建各波段数据集失败!"), MB_ICONWARNING,0); return 0; } for (int i=0; iGetRasterBand(i+1); if (poBand == NULL) { CString str; str.Format(_T("创建第%d波段数据集失败! "),i+1); AfxMessageBox(str, MB_ICONWARNING); return 0;
} } CImageInfoDlg dlg; dlg.Totalband=nBands; if(LorR==0) dlg.dlgType=1; else dlg.dlgType=2; dlg.DoModal(); int nXsize,nYsize; //图 像高宽 nXsize = poBand[0]->GetXSize(); nYsize = poBand[0]->GetYSize(); int maxSize=max(nXsize,nYsize); if (LorR==0) //左片
{ CPicTreeView *pView=(CPicTreeView*)(((CMainFrame*)AfxGetMainWnd())-> m_wndSplitter.GetPane(0,0)); CTreeCtrl& CtlTree=(CTreeCtrl&)pView->GetTreeCtrl (); //根节点 HTREEITEM htemroot=CtlTree.GetRootItem(); //左片 HTREEITEM htemleft=CtlTree.GetChildItem(htemroot); HTREEITEM htemdele=CtlTree.GetChildItem(htemleft); // htemdele=CtlTree.GetNextSiblingItem(htemdele); while (htemdele!=NULL) { HTREEITEM htemNext=CtlTree.GetNextItem(htemdele,TVGN_NEXT); CtlTree.DeleteItem(htemdele);
htemdele=htemNext; } if(600<=maxSize&&maxSize<=1200) nImgL=2; else { if (maxSize<=2500) nImgL=3; else { if (maxSize<=5000) nImgL=4; else nImgL=5; }
} pBitmapInfoL=new BITMAPINFO *[nImgL]; pDataL=new LPBYTE[nImgL]; pBitmapInfoL[0] = (BITMAPINFO*)new char[sizeof(BITMAPINFO) + sizeof(RGBQUAD) * (256)]; pBitmapInfoL[0]->bmiHeader.biClrUsed = 0; pBitmapInfoL[0]->bmiHeader.biBitCount = 8; pBitmapInfoL[0]->bmiHeader.biClrImportant = 0; pBitmapInfoL[0]->bmiHeader.biCompression=BI_RGB; pBitmapInfoL[0]->bmiHeader.biWidth = nXsize; pBitmapInfoL[0]->bmiHeader.biHeight = nYsize;
pBitmapInfoL[0]->bmiHeader.biPlanes = 1; pBitmapInfoL[0]->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);//sizeof(BITMAPINFO); pBitmapInfoL[0]->bmiHeader.biSizeImage = (nXsize*8+31)/32*4*nYsize; pBitmapInfoL[0]->bmiHeader.biXPelsPerMeter = 0; pBitmapInfoL[0]->bmiHeader.biYPelsPerMeter = 0; //为颜色表赋值 for (int i=0; i<256; i++) { pBitmapInfoL[0]->bmiColors.rgbBlue = i; pBitmapInfoL[0]->bmiColors.rgbGreen = i; pBitmapInfoL[0]->bmiColors.rgbRed = i; pBitmapInfoL[0]->bmiColors.rgbReserved = 0; } } else
分享到:
收藏