


版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、IPicture使用總結(jié)1、IPicture接口對(duì)象的創(chuàng)建方法1:直接通過文件創(chuàng)建LPCSTR szFileUrl;IPicture _pIPicture;OleLoadPicturePath(CComBSTR(szFileUrl), (LPUNKNOWN)NULL, 0, 0, IID_IPicture,(LPVOID_)&pIPicture)方法2:通過IStream來創(chuàng)建/ 加載電子地圖LPCSTR szFileUrl;IStream _pStream = NULL;IPicture _pIPicture = NULL;CFileStatus fstatus;CFile file
2、;LONG lFileSize;HGLOBAL hGlobal;if(file.Open(szFileUrl, CFile:modeRead) && file.GetStatus(szFileUrl, fstatus) && (lFileSize = fstatus.m_size) != -1)hGlobal = GlobalAlloc(GMEM_MOVEABLE, lFileSize);/ 開辟大內(nèi)存if(hGlobal != NULL)LPVOID pvData = NULL;pvData = GlobalLock(hGlobal);if(pvData !=
3、 NULL) file.ReadHuge(pvData, lFileSize); / 將圖片數(shù)據(jù)保存在內(nèi)存中GlobalUnlock(hGlobal);CreateStreamOnHGlobal(hGlobal, TRUE, &m_pIStream); / 創(chuàng)建流file.Close;elseGlobalFree(hGlobal);return;elsefile.Close;return;else/打開圖片失敗return;OleLoadPicture(m_pIStream, fstatus.m_size, TRUE, IID_IPicture, (LPVOID_)&m_pIP
4、icture);GlobalFree(hGlobal);2、通過IPicture來獲取圖片的尺寸OLE_SIZE_HIMETRIC hmPicWidth; OLE_YSIZE_HIMETRIC hmPicHeight; pIPicture->get_Width(&hmPicWidth); / 獲取圖像寬度pIPicture->get_Height(&hmPicHeight); / 獲取圖像高度/ 轉(zhuǎn)化單位為象素nPicWidth = MulDiv(hmPicWidth, GetDeviceCaps(GetDC->m_hDC, LOGPI_ELS_), HIME
5、TRIC_PER_INCH);nPicHeight = MulDiv(hmPicHeight, GetDeviceCaps(GetDC->m_hDC, LOGPI_ELSY), HIMETRIC_PER_INCH);3、通過IPicture來畫圖void ShowPicture(CDC _pDC)OLE_POS_HIMETRIC _Src; / 圖片中當(dāng)前顯示區(qū)域的_OLE_YPOS_HIMETRIC ySrc; / 圖片中當(dāng)前顯示區(qū)域的yOLE_SIZE_HIMETRIC c_Src; / 圖片中當(dāng)前顯示區(qū)域的寬度OLE_YSIZE_HIMETRIC cySrc; / 圖片中當(dāng)前顯示區(qū)
6、域的高度m_pIPicture->Render(_pDC, 0, 0, m_rcBo_.Width, m_rcBo_.Height, _Src, ySrc, c_Src, cySrc, NULL);4、將IPicture中的圖片保存起來BOOL SaveToFileFromIPicture(LPCSTR szFileName, IPicture _pPic)/ Create ILockBytes BufferILockBytes _plkbyt = NULL;CreateILockBytesOnHGlobal(NULL, TRUE, &plkbyt); / Create ISto
7、rageIStorage _pStorage = NULL;HRESULT hr = :StgCreateDocfileOnILockBytes(plkbyt,STGM_SHARE_E_CLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage);if (FAILED(hr)plkbyt->Release;plkbyt = NULL;return FALSE;/ Create IStreamIStream _pStream = NULL;hr = pStorage->CreateStream(L"PICTURE&quo
8、t;,STGM_SHARE_E_CLUSIVE | STGM_CREATE | STGM_READWRITE, 0, 0, &pStream);if (FAILED(hr)pStorage->Release;pStorage = NULL;plkbyt->Release;plkbyt = NULL;return FALSE;/ Copy Data Streamlong lSize;hr = pPic->SaveAsFile(pStream, TRUE, &lSize); if (FAILED(hr)pStream->Release;pStream = N
9、ULL;pStorage->Release;pStorage = NULL;plkbyt->Release;plkbyt = NULL;return FALSE;/ Get Statistics For Final Size Of Byte ArraySTATSTG statStg;hr = plkbyt->Stat(&statStg, STATFLAG_NONAME);if (FAILED(hr)pStream->Release;pStream = NULL;pStorage->Release;pStorage = NULL;plkbyt->Rel
10、ease;plkbyt = NULL;return FALSE;/ calculate "Pure" Picture Data, Must Be In a 512 Blocksdouble dbSkipFloat = (double(lSize) / 512); DWORD dwPicDataSize = 0;if(dbSkipFloat > DWORD(dbSkipFloat) dwPicDataSize = (DWORD)dbSkipFloat + 1;else dwPicDataSize = (DWORD)dbSkipFloat;dwPicDataSize =
11、dwPicDataSize _512; / Allocate Only The "Pure" Picture DataBYTE _pPicDataBuffer = (BYTE_)malloc(dwPicDataSize);if (pPicDataBuffer = NULL)pStream->Release;pStream = NULL;plkbyt->Release;pStorage->Release;pStorage = NULL;plkbyt = NULL;return FALSE;/ Read "Pure" Picture Dat
12、a to Buffer_ULARGE_INTEGER ulOffset;ulOffset.LowPart = 0;ulOffset.HighPart = 0;ulOffset.QuadPart = (DWORD)(statStg.cbSize.QuadPart - dwPicDataSize);DWORD dwRealDataSize;hr = plkbyt->ReadAt(ulOffset, pPicDataBuffer, dwPicDataSize, &dwRealDataSize);if (FAILED(hr)free(pPicDataBuffer);pPicDataBuf
13、fer = NULL;pStream->Release;pStream = NULL;pStorage->Release;pStorage = NULL;plkbyt->Release;plkbyt = NULL;return FALSE;/ Save "Pure" Picture Data to fileCFile fBmp; CFileE_ception e;if (!fBmp.Open(szFileName, CFile:typeBinary | CFile:modeCreate | CFile:modeWrite, &e)free(pPic
14、DataBuffer);pPicDataBuffer = NULL;pStream->Release;pStream = NULL;pStorage->Release;pStorage = NULL;plkbyt->Release;plkbyt = NULL;return FALSE;fBmp.Write(pPicDataBuffer, dwRealDataSize);fBmp.Close;free(pPicDataBuffer);pPicDataBuffer = NULL;pStream->Release;pStream = NULL;pStorage->Rel
15、ease;pStorage = NULL;plkbyt->Release;plkbyt = NULL;return TRUE;5、將IPicture中圖片按規(guī)定的尺寸保存BOOL CIPictureDlg:Save2File(LPCSTR szFileName, IPicture _pPic, int nWidth, int nHeight)/ create a new IPictureOLE_HANDLE hPic = NULL;if (FAILED(pPic->get_Handle(&hPic)return FALSE;HBITMAP hBmp = (HBITMAP)CopyImage(HANDLE)hPic,IMAGE_BITMAP, nWidth, nWidth, LR_CREATEDIBSECTION);if (hBmp = NULL)return FALSE;PICTDESC picDesc;picDesc.cbSizeofstruct = sizeof(PICTDESC);picDesc.picType = PICTYPE_BITMAP;picDesc.bmp.hbitmap = hBmp;IPicture _pNewPic = NULL;if (SUCCEEDED(OleCreateP
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度股東借款轉(zhuǎn)增注冊(cè)資本及利潤分配調(diào)整合同
- 2025年度電力線路運(yùn)維風(fēng)險(xiǎn)管理與合同
- 2025年度電子產(chǎn)品退貨換貨服務(wù)合同范本
- 二零二五年度航空航天項(xiàng)目三方合同違約責(zé)任說明
- 公共安全應(yīng)急救援預(yù)案制定指南
- 數(shù)據(jù)中心運(yùn)維服務(wù)合同及設(shè)備維護(hù)管理?xiàng)l款
- 中學(xué)生數(shù)學(xué)史故事征文
- 產(chǎn)品采購及供應(yīng)保障協(xié)議合同
- 企業(yè)信息化建設(shè)實(shí)施細(xì)則
- 企業(yè)資源共享合作協(xié)議書
- 2023版初中化學(xué)跨學(xué)科實(shí)踐活動(dòng)(化學(xué))
- 植物保護(hù)學(xué)通論-植物病害分析課件
- 藥品經(jīng)營質(zhì)量管理規(guī)范(GSP)實(shí)用教程教學(xué)課件
- 機(jī)械基礎(chǔ) 第2版全書電子教案
- 外研社一起英語四年級(jí)下冊(cè)課文
- DB32-T 2705-2014公路工程地質(zhì)勘察監(jiān)理規(guī)程-(高清現(xiàn)行)
- After-Effects影視特效設(shè)計(jì)教程完整版全套ppt課件
- 羊營養(yǎng)代謝病
- 醫(yī)療設(shè)備清單
- 《夏夜多美》課件(ppt)
- 社區(qū)院落停車管理制度
評(píng)論
0/150
提交評(píng)論