bmp转ico

ico文件比较特殊,一般都不能转,这里从网友那儿看到了一段把bmp转ico的代码,没有试过,先留着以后用的上的时候,拿出来试试。多谢网友的分享。
CFileDialog   DlgFileOpen(   TRUE, "*.ICO ",NULL,NULL, "bmp文件(*.BMP)|*.BMP|| "); 
if(DlgFileOpen.DoModal()==IDCANCEL) 
return; 
HBITMAP   hBmpClr=   (HBITMAP)   ::LoadImage(AfxGetResourceHandle(), 
                                             DlgFileOpen.GetFileName(), 
                                             IMAGE_BITMAP, 
                                             0,0, 
                                             LR_DEFAULTCOLOR|LR_DEFAULTSIZE|LR_LOADFROMFILE 
                                             ); 

CDC   dcMemSrc,dcMemDst; 
dcMemSrc.CreateCompatibleDC   (NULL); 
dcMemDst.CreateCompatibleDC(NULL); 

BITMAP   bmp; 
::GetObject   (hBmpClr,   sizeof   (BITMAP),   (LPVOID)   &bmp); 

CBitmap   bmpClr; 
dcMemSrc.SelectObject(hBmpClr); 
bmpClr.CreateCompatibleBitmap(&dcMemSrc,32,32   ); 
HBITMAP   hOldBmp=(HBITMAP)dcMemDst.SelectObject(bmpClr); 
COLORREF   clrMask=dcMemSrc.GetPixel(CPoint(0,0)); 
dcMemDst.FillSolidRect(0,0,32,32   ,clrMask); 
dcMemDst.StretchBlt(0,0,32,32   ,&dcMemSrc,0,0,bmp.bmWidth,bmp.bmHeight,SRCINVERT); 

hBmpClr=(HBITMAP)dcMemDst.SelectObject(hOldBmp); 


HBITMAP   hMaskBmp; 
CBitmap   bmpMask; 
bmpMask.CreateCompatibleBitmap(&dcMemSrc,32,32   ); 

hOldBmp   =   (HBITMAP)   dcMemSrc.SelectObject   (bmpMask); 
dcMemSrc.FillSolidRect(CRect   (0,   0,   32,   32   ),RGB(255,255,255)); 
hMaskBmp=(HBITMAP)dcMemSrc.SelectObject(hOldBmp); 
ICONINFO   IconInfo; 
IconInfo.fIcon=TRUE; 
IconInfo.hbmColor=hBmpClr; 
IconInfo.hbmMask=hMaskBmp; 
IconInfo.xHotspot=0; 
IconInfo.yHotspot=0; 
HICON   hIcon=CreateIconIndirect(&IconInfo); 

::DeleteObject(hBmpClr); 
::DeleteObject(hMaskBmp); 

你可能感兴趣的:(image,null)