rasterio的用法參考:
在mfc專案中新增乙個對話方塊dlgfastshow,新增乙個按鈕 ,在標頭檔案中新增如下**:
1public
:2 gdaldataset*m_pdataset;
3double m_dscale; //
現有圖框與影象的比值45
intm_iminx;
6int
m_iminy;
7int
m_imaxx;
8int
m_imaxy;
9void showraster();
在實現檔案中新增如下**:
1void
dlgfastshow::onbnclickedbtnopenimage()2
19double padftransform[6] = ;
20 m_pdataset->getgeotransform(padftransform);
21showraster();22}
23}24void
dlgfastshow::showraster()
25;
3435 m_dscale = dataheight > datawidth ?dataheight : datawidth;
36int iviewheight = 478
; 37 m_dscale = iviewheight/m_dscale;
3839
int isize = gdalgetdatatypesize(gdt_byte) / 8;//
以位元組為單位
40int iscalewidth = static_cast(datawidth*m_dscale+0.5
);
41int iscaleheight = static_cast(dataheight*m_dscale+0.5
);
快取數目: %d %d
",iscalewidth,iscaleheight);
43 iscalewidth = (iscalewidth*8+31)/32*4
;取整數目: %d
",iscalewidth);
45afxmessagebox(ex);
46 unsigned char* pbuffer = new unsigned char[iscalewidth*iscaleheight*3
];
47 cplerr err = m_pdataset->rasterio(gf_read, 0, 0,datawidth, dataheight, pbuffer, iscalewidth, iscaleheight,gdt_byte, 3, band_list, isize*3, isize*iscalewidth*3, isize); //
讀取3個波段的資料
4849 unsigned char* pdatabuffer =null;
50if (databands >=3
) 51
54else
55
6162
/*cbitmap bitmap;
63int flag=bitmap.createbitmap(iscalewidth, iscaleheight,1,24,pdatabuffer );
*/64
//int flag=bitmap.createcompatiblebitmap(iscalewidth, iscaleheight,1,32,pdatabuffer );
65/*
if (flag==0)
66*/
69//
hbitmap hbmp;
//儲存cbitmap載入的點陣圖的控制代碼
70//
hbmp = (hbitmap)bitmap.getsafehandle();
//獲取bitmap載入點陣圖的控制代碼
7172
73//
cclientdc dc(this);
74//
bitmap bm;
75//
bitmap.getobject(sizeof (bitmap),&bm);
76//
cdc dcmem;
77//
dcmem.createcompatibledc(&dc);
78//
cbitmap *poldbmp=dcmem.selectobject(&bitmap);
79//
cdc *pdc=&dc;
80//
pdc->bitblt(0,0,bm.bmwidth,bm.bmheight,&dcmem,0,0,srccopy);
81//
dcmem.selectobject(poldbmp);
8283
84cdc dc;
85 cclientdc cdc(this
);86
87dc.attach(cdc.m_hdc);
8889
cdc memdc;
90 memdc.createcompatibledc(&dc);
9192
cbitmap bmp;
93 bmp.createcompatiblebitmap(&dc,500,500
);94 memdc.selectobject(&bmp);
9596
bitmapinfo bmpinfo;
97 bmpinfo.bmiheader.bisize = sizeof
(bitmapinfoheader);
98 bmpinfo.bmiheader.biwidth =iscalewidth;
99 bmpinfo.bmiheader.biheight = -iscaleheight;
100//
bmpinfo.bmiheader.biwidth = 487;
101//
bmpinfo.bmiheader.biheight = -500;
102 bmpinfo.bmiheader.biplanes = 1
;103 bmpinfo.bmiheader.bibitcount = 24;//
24位色
104 bmpinfo.bmiheader.bicompression =bi_rgb;
105 bmpinfo.bmiheader.bisizeimage = 0
;106 bmpinfo.bmiheader.bixpelspermeter = 3000
;107 bmpinfo.bmiheader.biypelspermeter = 3000
;108 bmpinfo.bmiheader.biclrused = 0
;109 bmpinfo.bmiheader.biclrimportant = 0
;110
111//
每行位元組數,4位元組對齊
112 /*long nlnbytes = (487+3)/4*4*3;
113
114 byte *pdata = new byte[nlnbytes*500];
115 memset(pdata,0,nlnbytes*500);
116 for(int i=10; i<90; i++)
117 */
121122 setdibits(dc.m_hdc,bmp,0,iscaleheight,pdatabuffer,&bmpinfo,dib_rgb_colors);
123//delete pdata;
124 cdc.bitblt(0,0,500,500,&memdc,0,0
,srccopy);
125delete pdatabuffer;
126127 }
存在問題:螢幕一重新整理,繪製的影象就沒有了。
主要ddb(裝置相關位圖)和dib(裝置無關位圖)的區別。採用了createcompatiblebitmap將byte陣列建立為位圖,採用createbitmap始終創只能建黑白影象。
PMD格式模型的讀取和顯示
已經五月了,花了超過十天的時間研究終於出成果了,寫一篇日誌紀念一下。pmd,全稱polygon model document,是一種三維模型格式,主要在mikumikudance和pmdeditor等中使用。而關於格式的說明就更少了,所以我的研究主要參考 itsuhane的mmd庫。pmd格式檔案也...
PCL點雲的基本讀取和顯示
廢話不多說,直接上 這是最基本的讀取與顯示,皆是利用pcl庫 include 標準輸入輸出流 include pcl的pcd格式檔案的輸入輸出標頭檔案 include pcl對各種格式的點的支援標頭檔案 include int main int argc,char argv std cout loa...
Python 二進位制檔案的讀取和顯示
1.編寫程式,將包含學生成績的字典儲存為二進位制檔案,然後再讀取內容並顯示。import pickle keys 湘玉 老白 芙蓉 秀才 values 90,85,89,92 dictionary dict zip keys,values print dictionary with open sco...