|
已经找到一个范例,并改写成功~
- // 获取指定图像的缩略图
- HBITMAP ImageStatic::GetImageThumbnail(LPCTSTR szFileName,int nWidth, int nHeight)
- {
- HRESULT hr;
- /*CBitmap ;*/
- HBITMAP memBmp=0;
- CWindowDC dc(0);
- CDC memDC;
- memDC.CreateCompatibleDC(&dc);
- memBmp=CreateCompatibleBitmap(dc.GetSafeHdc(),nWidth,nHeight);
- HGDIOBJ hOldBitmap = memDC.SelectObject(memBmp);
- memDC.SelectObject(&memBmp);
- CRect rect(0,0,nWidth,nHeight);
- if(m_pImageThumbnail)
- {
- m_pImageThumbnail->Release();
- m_pImageThumbnail=NULL;
- }
- hr=pImagingFactory->CreateImageFromFile(szFileName,&m_pImageThumbnail);
- if(hr == S_OK)
- {
- //m_pImageThumbnail->GetImageInfo(&imageinfo);
- TRACE(_T("Thumbnail LOAD Success!"));
- /*InvalidateRect(&m_rectStaticClient);*/
- }
- else
- {
- TRACE(_T("Thumbnail LOAD ERROR"));
- }
- hr=m_pImageThumbnail->GetThumbnail(nWidth,nHeight,&m_pImageThumbnail);
- if(hr==S_OK)
- {
- TRACE(_T("GET THUMBNAIL SUCCESEE"));
- m_pImageThumbnail->Draw(memDC.GetSafeHdc(), &rect,NULL);
- memDC.SelectObject(hOldBitmap);
-
- }
- return memBmp;
- }
复制代码 |
|