




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、在vc 6中設(shè)置好opengl開發(fā)環(huán)境,視口的大小設(shè)置成與客戶區(qū)大小一樣,欲將客戶區(qū)的圖像保存為24位真彩色位圖,源代碼如下,可是存在這樣的問題:程序運行,窗口剛創(chuàng)建時(此時不拉動邊框改變客戶區(qū)大?。?,可以正常保存。當(dāng)最大化窗口或?qū)⒆畲蠡翱趶?fù)原,都可以正常保存。而當(dāng)人為拉動邊框改變客戶區(qū)大小后,保存的圖像出現(xiàn)問題,如下:調(diào)試信息如下:源代碼如下:void CMySDOpenGLView:OnCaptureImage() /保存位圖的消息函數(shù)/ TODO: Add your command handler code hereCString s("Windows Bitmap(*.bm
2、p)|*.bmp|");CFileDialog fd(FALSE,"bmp",0,OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST,s);if(fd.DoModal()=IDOK)BeginWaitCursor();int viewport4;glGetIntegerv(GL_VIEWPORT,viewport); bool success = false; DWORD nFileType=0;if(strcmp(fd.GetFileExt(),"bmp")=0) nFileType=
3、1; if(nFileType=1)success=m_imagecapture.CaptureGLBufferToBMP(fd.GetPathName(),/調(diào)用保存位圖類的 viewport0,viewport1,/函數(shù)保存位圖 viewport2,viewport3);else / Invalid file extension specified. MessageBox("WTF? Unknown file extension specified for screen capture.n","Error",MB_OK); if (!success)
4、 char errorMsg64; if(nFileType = 0) sprintf(errorMsg, "Specified file extension is not recognized."); else sprintf(errorMsg, "Could not save image file."); MessageBox(errorMsg, "Error", MB_OK | MB_ICONERROR); EndWaitCursor();保存位圖類的定義class CImageCapturepublic:CImageCaptu
5、re();virtual CImageCapture();bool CaptureGLBufferToBMP(CString filename, int x, int y, int width, int height);int WriteBitmapFile(CString filename, int width, int height, unsigned char *imageData);CImageCapture:CImageCapture()CImageCapture:CImageCapture()bool CImageCapture:CaptureGLBufferToBMP(CStri
6、ng filename, int x, int y, int width, int height)void* imageData = malloc(width*height*3);/ allocate memory for the imageDatamemset(imageData, 0, width*height*3); / clear imageData memory contents/ read the image data from the windowglReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (unsign
7、ed char*)imageData);/ write the image data to a fileWriteBitmapFile(filename, width, height, (unsigned char*)imageData);/ free the image data memoryfree(imageData);return true;/ WriteBitmapFile()/ desc: takes image data and saves it into a 24-bit RGB .BMP file/ with width X height dimensionsint CIma
8、geCapture:WriteBitmapFile(CString filename, int width, int height, unsigned char *imageData)FILE *filePtr;/ file pointerBITMAPFILEHEADER bitmapFileHeader;/ bitmap file headerBITMAPINFOHEADER bitmapInfoHeader;/ bitmap info headerunsigned int imageIdx;/ used for swapping RGB->BGRunsigned char tempR
9、GB;/ used for swapping/ open file for writing binary modefilePtr = fopen(filename, "wb");if (!filePtr)return 0;/ define the bitmap file headerbitmapFileHeader.bfSize = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+(4*(width*24+31)/32) * height);bitmapFileHeader.bfType = 0x4D42;bitmapFi
10、leHeader.bfReserved1 = 0;bitmapFileHeader.bfReserved2 = 0;bitmapFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);/ define the bitmap information headerbitmapInfoHeader.biSize = sizeof(BITMAPINFOHEADER);bitmapInfoHeader.biPlanes = 1;bitmapInfoHeader.biBitCount = 24;/ 24-bitb
11、itmapInfoHeader.biCompression = BI_RGB;/ no compressionbitmapInfoHeader.biSizeImage = 4*(width*24+31)/32) * height;/ width * height * (RGB bytes)bitmapInfoHeader.biXPelsPerMeter = 0;bitmapInfoHeader.biYPelsPerMeter = 0;bitmapInfoHeader.biClrUsed = 0;bitmapInfoHeader.biClrImportant = 0;bitmapInfoHead
12、er.biWidth = width;/ bitmap widthbitmapInfoHeader.biHeight = height;/ bitmap height/ switch the image data from RGB to BGRfor (imageIdx = 0; imageIdx < bitmapInfoHeader.biSizeImage; imageIdx+=3)tempRGB = imageDataimageIdx;imageDataimageIdx = imageDataimageIdx + 2;imageDataimageIdx + 2 = tempRGB;/
13、add empty Byte to every row, if this row cannot be divided exactly by 4. unsigned char *imageDataAfterAdding =(unsigned char *) malloc(4*(width*24+31)/32) * height);memset(imageDataAfterAdding, 0, 4*(width*24+31)/32) * height); for(int k=0; k<height; k+)for(int i=0; i<width*3; i+)imageDataAfterAddingk*width*3+i+k*(4*(width*24+31)/32)-width*3)= imageDatak*width*3+i;/ write the bitmap file headerfwrite(&bitmapFileHeader, 1, sizeof(BITMAPFILEHEADER), filePtr);/ write the bitmap info headerfwrite(&bitmapInfoHeader, 1, sizeof(B
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 排水溝穿越道路施工方案
- 水污染治理工程施工方案
- 濮陽拉森鋼板樁施工方案
- 遼寧民宿文旅施工方案
- 幼兒園獲獎公開課:小班數(shù)學(xué)《草裙舞》教學(xué)設(shè)計
- 燈箱廣告改造施工方案
- 正安建筑打樁施工方案
- 數(shù)控加工工藝與編程技術(shù)基礎(chǔ) 教案 模塊三 項目二 綜合件的加工(3-4)
- 水稻種植中多發(fā)病蟲害的發(fā)生特點及針對性綠色防控技術(shù)具體分析
- 【專精特新】折疊屏手機(jī)行業(yè)市場份額證明材料(智研咨詢發(fā)布)
- GB∕T 7260.40-2020 不間斷電源系統(tǒng) UPS 第4部分:環(huán)境 要求及報告
- 中學(xué)生心理健康診斷測驗-MHT量表
- 2022年CAD快捷鍵-CAD常用快捷鍵命令大全
- 流感病人的護(hù)理ppt課件
- 高邊坡施工危險源辨識及分析
- 【李建西醫(yī)案鑒賞系列】三當(dāng)歸四逆湯治療頸腫案
- 安全文明施工管理(EHS)方案(24頁)
- 結(jié)構(gòu)化思維PPT通用課件
- 劉姥姥進(jìn)大觀園課本劇劇本3篇
- 2022年拖拉機(jī)駕駛?cè)丝荚噮⒖碱}庫(含答案)
- 產(chǎn)品承認(rèn)書客(精)
評論
0/150
提交評論