急救IPictrue显示出来JPg怎样保存的为BMP图片
qxf32 2008-03-29 09:29:50 void CBmpChangeView::ShowJpg(CDC *pDC)
{
::CoInitialize(NULL); // COM 初始化
CFile file;
CBmpChangeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
file.Open(pDoc->filename, CFile::modeRead | CFile::shareDenyNone ); // 读入文件内容
DWORD dwSize = file.GetLength();
hMem = ::GlobalAlloc( GMEM_MOVEABLE, dwSize );
lpBuf = ::GlobalLock( hMem );
file.ReadHuge( lpBuf, dwSize );
file.Close();
::GlobalUnlock( hMem );
IStream * pStream = NULL;
IPicture * pPicture = NULL;
// 由 HGLOBAL 得到 IStream,参数 TRUE 表示释放 IStream 的同时,释放内存
hr = ::CreateStreamOnHGlobal( hMem, TRUE, &pStream );
ASSERT ( SUCCEEDED(hr) );
hr = ::OleLoadPicture( pStream, dwSize, TRUE, IID_IPicture, ( LPVOID * )&pPicture );
ASSERT(hr==S_OK);
long cx1,cy1;
long nWidth,nHeight; // 宽高,MM_HIMETRIC 模式,单位是0.01毫米
pPicture->get_Width( &nWidth ); // 宽
pPicture->get_Height( &nHeight ); // 高
CString s1;
/* s1.Format("%d",nWidth);
AfxMessageBox(s1);
s1.Format("%d",nHeight);
AfxMessageBox(s1);
*/
CRect lpRect;
CMainFrame *m_cmainframe=(CMainFrame *)AfxGetMainWnd();
m_cmainframe->GetClientRect(lpRect);
if( !pDoc->m_fullscrean)
{ CRect lpect;
if(pDoc->zoomfactor>0)
{
CSize sz( nWidth* (pDoc->zoomfactor), nHeight* (pDoc->zoomfactor) );
pDC->HIMETRICtoDP( &sz ); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位
cx1=lpRect.right/2-sz.cx/2;//居中显示
cy1=lpRect.bottom/2-sz.cy/2;//居中显示
pPicture->Render(pDC->m_hDC,cx1,cy1,sz.cx,sz.cy,
0,nHeight,nWidth,-nHeight,NULL);
m_rect.left=cx1;
m_rect.top=cy1;
}
else
{CSize sz( nWidth/ (-pDoc->zoomfactor), nHeight/ (-pDoc->zoomfactor) );
pDC->HIMETRICtoDP( &sz ); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位
cx1=lpRect.right/2-sz.cx/2;//居中显示
cy1=lpRect.bottom/2-sz.cy/2;//居中显示
pPicture->Render(pDC->m_hDC,cx1,cy1,sz.cx,sz.cy,
0,nHeight,nWidth,-nHeight,NULL);
}
}
else
{////////全屏下按窗口尺寸显示////////
if(!pDoc->m_factsize)
{
CRect rect; GetClientRect(&rect);
pPicture->Render(pDC->m_hDC,0,0,rect.Width(),rect.Height(),
0,nHeight,nWidth,-nHeight,NULL);
}
else
{////////全屏下按实际大小显示////////
CSize sz( nWidth, nHeight);
pDC->HIMETRICtoDP( &sz ); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位
cx1=lpRect.right/2-sz.cx/2;//居中显示
cy1=lpRect.bottom/2-sz.cy/2;//居中显示
pPicture->Render(pDC->m_hDC,cx1,cy1,sz.cx,sz.cy,
0,nHeight,nWidth,-nHeight,NULL);
}
}
if ( pPicture ) pPicture->Release();// 释放 IPicture 指针
if ( pStream ) pStream->Release(); // 释放 IStream 指针,同时释放了 hMem
::CoUninitialize();
}
现在图片已经显示了出来。但是不知怎么保存用这个IPictrue来显示的图片