|
|
@@ -42,56 +42,61 @@ int CBitmapHelper::GetCBitmapHeight(const CBitmap & cbm)
|
|
|
|
|
|
BOOL CBitmapHelper::GetCBitmap(void *pClip2, CDC *pDC, CBitmap *pBitMap, int nMaxHeight)
|
|
|
{
|
|
|
- BOOL bRet = FALSE;
|
|
|
-
|
|
|
CClipFormat *pClip = (CClipFormat *)pClip2;
|
|
|
|
|
|
- if(pClip->m_cfType == CF_DIB ||
|
|
|
- pClip->m_cfType == theApp.m_PNG_Format)
|
|
|
- {
|
|
|
- if(pBitMap)
|
|
|
- {
|
|
|
- if (nMaxHeight < INT_MAX)
|
|
|
- {
|
|
|
- Gdiplus::Bitmap *gdipBitmap = pClip->CreateGdiplusBitmap();
|
|
|
-
|
|
|
- if (gdipBitmap != NULL &&
|
|
|
- gdipBitmap->GetHeight() > 0 &&
|
|
|
- gdipBitmap->GetWidth() > 0)
|
|
|
- {
|
|
|
- int nHeight = min(nMaxHeight, (int)gdipBitmap->GetHeight());
|
|
|
- int nWidth = (nHeight * gdipBitmap->GetWidth()) / gdipBitmap->GetHeight();
|
|
|
-
|
|
|
- //do the resize
|
|
|
- pBitMap->CreateCompatibleBitmap(pDC, nWidth, nHeight);
|
|
|
- ASSERT(pBitMap->m_hObject != NULL);
|
|
|
+ if(pClip->m_cfType != CF_DIB &&
|
|
|
+ pClip->m_cfType != theApp.m_PNG_Format)
|
|
|
+ return false;
|
|
|
+ if(!pBitMap)
|
|
|
+ return false;
|
|
|
+ if (nMaxHeight < 0)
|
|
|
+ return false;
|
|
|
|
|
|
- CDC MemDc2;
|
|
|
- MemDc2.CreateCompatibleDC(pDC);
|
|
|
-
|
|
|
- CBitmap* oldBitmap2 = MemDc2.SelectObject(pBitMap);
|
|
|
+ Gdiplus::Bitmap *gdipBitmap = pClip->CreateGdiplusBitmap();
|
|
|
+ if (gdipBitmap == NULL)
|
|
|
+ {
|
|
|
+ delete gdipBitmap;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- Gdiplus::ImageAttributes attrs;
|
|
|
- Gdiplus::Rect dest(0, 0, nWidth, nHeight);
|
|
|
+ const UINT gdipHeight = gdipBitmap->GetHeight();
|
|
|
+ const UINT gdipWidth = gdipBitmap->GetWidth();
|
|
|
+ if (gdipHeight == 0 || gdipWidth == 0)
|
|
|
+ {
|
|
|
+ delete gdipBitmap;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- Gdiplus::Graphics graphics(MemDc2);
|
|
|
- graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
|
|
|
- graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf);
|
|
|
+ const int nHeight = min(nMaxHeight, (int)gdipHeight);
|
|
|
+ const int nWidth = (nHeight * gdipWidth) / gdipHeight;
|
|
|
|
|
|
- graphics.DrawImage(gdipBitmap, dest, 0, 0, gdipBitmap->GetWidth(), gdipBitmap->GetHeight(), Gdiplus::UnitPixel, &attrs);
|
|
|
+ //do the resize
|
|
|
+ pBitMap->CreateCompatibleBitmap(pDC, nWidth, nHeight);
|
|
|
+ ASSERT(pBitMap->m_hObject != NULL);
|
|
|
|
|
|
- MemDc2.SelectObject(oldBitmap2);
|
|
|
- }
|
|
|
+ CDC MemDc2;
|
|
|
+ MemDc2.CreateCompatibleDC(pDC);
|
|
|
|
|
|
- delete gdipBitmap;
|
|
|
- }
|
|
|
+ CBitmap* oldBitmap2 = MemDc2.SelectObject(pBitMap);
|
|
|
|
|
|
- bRet = TRUE;
|
|
|
- }
|
|
|
- }
|
|
|
+ Gdiplus::Rect dest(0, 0, nWidth, nHeight);
|
|
|
+ Gdiplus::ImageAttributes attrs;
|
|
|
+ Gdiplus::Graphics graphics(MemDc2);
|
|
|
|
|
|
+ Gdiplus::InterpolationMode interpolationMode = Gdiplus::InterpolationModeHighQualityBicubic;
|
|
|
+ if (CGetSetOptions::GetFastThumbnailMode())
|
|
|
+ {
|
|
|
+ interpolationMode = Gdiplus::InterpolationModeNearestNeighbor;
|
|
|
+ }
|
|
|
+ graphics.SetInterpolationMode(interpolationMode);
|
|
|
+ graphics.SetCompositingMode(Gdiplus::CompositingModeSourceOver);
|
|
|
+ graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf);
|
|
|
+ graphics.DrawImage(gdipBitmap, dest, 0, 0, gdipWidth, gdipHeight, Gdiplus::UnitPixel, &attrs);
|
|
|
|
|
|
- return bRet;
|
|
|
+ MemDc2.SelectObject(oldBitmap2);
|
|
|
+ delete gdipBitmap;
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
BOOL CBitmapHelper::GetCBitmap(CClipFormats &clips, CDC* pDC, CBitmap* pBitMap, BOOL horizontal)
|