结果图能够显示,但大小没能得到改变,大家看看问题在哪儿,谢谢!
CImageList m_ImageListThumb; // image list holding the thumbnails
HBITMAP hBitmap;
hBitmap=ImageLoad(_T("C:\\WINDOWS\\Desktop\\vc\\1.jpg")); //函数ImageLoad返回HBITMAP
HDC hMemDC = ::CreateCompatibleDC(NULL);
::SelectObject(hMemDC, hBitmap);
pImage = new CBitmap();
pImage->Attach(hBitmap);
BITMAP bmpX;
pImage->GetBitmap(&bmpX);
char* bmpBuffer=(char*)GlobalAlloc(GPTR,bmpX.bmWidthBytes*bmpX.bmHeight);//allocate memory
DWORD dwValue=pImage->GetBitmapBits(bmpX.bmWidthBytes *bmpX.bmHeight,bmpBuffer);//Get the bitmap bits
BITMAPINFO the_bmInfo;
ZeroMemory(&the_bmInfo,sizeof(the_bmInfo));
the_bmInfo.bmiHeader.biSize = sizeof(BITMAPINFO);
the_bmInfo.bmiHeader.biBitCount = bmpX.bmBitsPixel;
the_bmInfo.bmiHeader.biHeight = -bmpX.bmHeight;
the_bmInfo.bmiHeader.biPlanes = 1;
the_bmInfo.bmiHeader.biWidth = bmpX.bmWidth;
GlobalFree((HGLOBAL)bmpBuffer);//Free memory
//
::StretchDIBits(hMemDC, (THUMBNAIL_WIDTH-the_bmInfo.bmiHeader.biWidth)/2,
(THUMBNAIL_HEIGHT-the_bmInfo.bmiHeader.biHeight)/2,
the_bmInfo.bmiHeader.biWidth,
the_bmInfo.bmiHeader.biHeight,
//THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT,
0, 0,
the_bmInfo.bmiHeader.biWidth,
the_bmInfo.bmiHeader.biHeight,
bmpBuffer,
&the_bmInfo,
DIB_RGB_COLORS,
SRCCOPY);pImage = new CBitmap();
pImage->Attach(hBitmap);// add bitmap to our image list
m_ImageListThumb.Replace(i, pImage, NULL);
m_ListThumbnail.InsertItem(i, _T("1.jpg"), i); //m_ListThumbnail为CListCtrl
CImageList m_ImageListThumb; // image list holding the thumbnails
HBITMAP hBitmap;
hBitmap=ImageLoad(_T("C:\\WINDOWS\\Desktop\\vc\\1.jpg")); //函数ImageLoad返回HBITMAP
HDC hMemDC = ::CreateCompatibleDC(NULL);
::SelectObject(hMemDC, hBitmap);
pImage = new CBitmap();
pImage->Attach(hBitmap);
BITMAP bmpX;
pImage->GetBitmap(&bmpX);
char* bmpBuffer=(char*)GlobalAlloc(GPTR,bmpX.bmWidthBytes*bmpX.bmHeight);//allocate memory
DWORD dwValue=pImage->GetBitmapBits(bmpX.bmWidthBytes *bmpX.bmHeight,bmpBuffer);//Get the bitmap bits
BITMAPINFO the_bmInfo;
ZeroMemory(&the_bmInfo,sizeof(the_bmInfo));
the_bmInfo.bmiHeader.biSize = sizeof(BITMAPINFO);
the_bmInfo.bmiHeader.biBitCount = bmpX.bmBitsPixel;
the_bmInfo.bmiHeader.biHeight = -bmpX.bmHeight;
the_bmInfo.bmiHeader.biPlanes = 1;
the_bmInfo.bmiHeader.biWidth = bmpX.bmWidth;
GlobalFree((HGLOBAL)bmpBuffer);//Free memory
//
::StretchDIBits(hMemDC, (THUMBNAIL_WIDTH-the_bmInfo.bmiHeader.biWidth)/2,
(THUMBNAIL_HEIGHT-the_bmInfo.bmiHeader.biHeight)/2,
the_bmInfo.bmiHeader.biWidth,
the_bmInfo.bmiHeader.biHeight,
//THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT,
0, 0,
the_bmInfo.bmiHeader.biWidth,
the_bmInfo.bmiHeader.biHeight,
bmpBuffer,
&the_bmInfo,
DIB_RGB_COLORS,
SRCCOPY);pImage = new CBitmap();
pImage->Attach(hBitmap);// add bitmap to our image list
m_ImageListThumb.Replace(i, pImage, NULL);
m_ListThumbnail.InsertItem(i, _T("1.jpg"), i); //m_ListThumbnail为CListCtrl
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货