123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- #include "stdafx.h"
- #include "LYFZIPManage.h"
- #include "JPEG.h"
- CPicture::CPicture()
- {
- }
- CPicture::~CPicture()
- {
- }
- void CPicture::UnloadPicture()
- {
- if(m_pPict != NULL){
- m_pPict->Release();
- m_pPict = NULL;
- }
- }
- BOOL CPicture::Load(HINSTANCE hInstance,LPCTSTR lpszResourceName, LPCSTR ResourceType)
- {
- HGLOBAL hGlobal = NULL;
- HRSRC hSource = NULL;
- LPVOID lpVoid = NULL;
- int nSize = 0;
- BOOL bResult=FALSE;
- if(m_pPict != NULL) UnloadPicture();
- hSource = FindResource(hInstance, lpszResourceName, ResourceType);
- if(hSource == NULL)
- {
-
- return(FALSE);
- }
- hGlobal = LoadResource(hInstance, hSource);
- if(hGlobal == NULL)
- {
-
-
- return(FALSE);
- }
- lpVoid = LockResource(hGlobal);
- if(lpVoid == NULL)
- {
-
- return(FALSE);
- }
- nSize = (UINT)SizeofResource(hInstance, hSource);
- if(LoadPictureData((BYTE*)hGlobal, nSize)) bResult = TRUE;
- UnlockResource(hGlobal);
- FreeResource(hGlobal);
- return(bResult);
- }
- BOOL CPicture::Load(CString sFilePathName)
- {
-
- BOOL bResult = FALSE;
- CFile PictureFile;
- CFileException e;
- int nSize = 0;
- if(m_pPict != NULL) UnloadPicture();
- if(PictureFile.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e))
- {
- nSize = PictureFile.GetLength();
- BYTE* pBuffer = new BYTE[nSize];
-
- if(PictureFile.Read(pBuffer, nSize) > 0)
- {
- if(LoadPictureData(pBuffer, nSize)) bResult = TRUE;
- }
- PictureFile.Close();
- delete [] pBuffer;
- }
- else
- {
- TCHAR szCause[255];
- e.GetErrorMessage(szCause, 255, NULL);
-
-
- bResult = FALSE;
- }
- return(bResult);
- }
- BOOL CPicture::LoadPictureData(BYTE *pBuffer, int nSize)
- {
- BOOL bResult = FALSE;
- HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nSize);
- if(hGlobal == NULL)
- {
-
- return(FALSE);
- }
- void* pData = GlobalLock(hGlobal);
- memcpy(pData, pBuffer, nSize);
- GlobalUnlock(hGlobal);
- IStream* pStream = NULL;
- if(CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK)
- {
- HRESULT hr;
- if((hr = OleLoadPicture(pStream, nSize, FALSE, IID_IPicture, (LPVOID *)&m_pPict)) == E_NOINTERFACE)
- {
-
-
- return(FALSE);
- }
- else
- {
- pStream->Release();
- pStream = NULL;
- bResult = TRUE;
-
- }
- }
-
- GlobalFree(hGlobal);
- return(bResult);
- }
- void CPicture::Render(CDC* pDC, LPRECT pDrawRect, LPRECT pSrcRect,LPCRECT prcWBounds)
- {
-
- if(pDC == NULL || m_pPict == NULL) return ;
- CRect recrDest(pDrawRect);
- long Width = 0;
- long Height = 0;
- m_pPict->get_Width(&Width);
- m_pPict->get_Height(&Height);
- CRect SrcRect(0,0,Width,Height);
- if(pSrcRect){
- SrcRect=*pSrcRect;
- }
- CRect DrawRect(pDrawRect);
- HRESULT hrP = NULL;
- hrP = m_pPict->Render(pDC->m_hDC,
- DrawRect.left,
- DrawRect.top,
- DrawRect.Width(),
- DrawRect.Height(),
- SrcRect.left,
- SrcRect.top,
- SrcRect.Width(),
- SrcRect.Height(),
- prcWBounds);
- if (SUCCEEDED(hrP)) return;
- AfxThrowMemoryException();
- return;
- }
- LONG CPicture::get_Height()
- {
- LONG nHeight = 0;
- if (m_pPict != NULL)
- {
- m_pPict->get_Height(&nHeight);
- }
- return nHeight;
- }
- LONG CPicture::get_Width()
- {
- LONG nWidth = 0;
- if (m_pPict != NULL)
- {
- m_pPict->get_Width(&nWidth);
- }
- return nWidth;
- }
- void CPicture::RenderBmp(CDC *pDC, LPRECT pDrawRect, LPRECT pSrcRect, LPCRECT prcWBounds)
- {
-
- if(pDC == NULL || m_pPict == NULL) return ;
- CRect recrDest(pDrawRect);
- long Width = 0;
- long Height = 0;
- m_pPict->get_Width(&Width);
- m_pPict->get_Height(&Height);
- CRect SrcRect(0,0,Width,Height);
- if(pSrcRect){
- SrcRect=*pSrcRect;
- }
- CRect DrawRect(pDrawRect);
- HRESULT hrP = NULL;
- hrP = m_pPict->Render(pDC->m_hDC,
- DrawRect.left,
- DrawRect.bottom-1,
- DrawRect.Width(),
- -DrawRect.Height()+1,
- SrcRect.left,
- SrcRect.top,
- SrcRect.Width(),
- SrcRect.Height()-1,
- prcWBounds);
- if (SUCCEEDED(hrP)) return;
- AfxThrowMemoryException();
- return;
- }
|