Icon to Bitmap Conversion Asked by Pah_g in Programming Languages Tags: bitmap, hicon I am facing a problem in converting an icon to a bitmap. To copy a bitmap to another bitmap following code works fine /*for bitmap*/ HBITMAP _hbmp = LOADIMAG(...); //creating a source memory DC and selecting a bitmap in it HDC srcDC = CreateCompatibleDC(::GetDC(m_hWnd)); SelectObject(srcDC,(HICON)_hbmp); //creating a destination memory DC and selecting a memory bitmap to it HDC desDC = CreateCompatibleDC(::GetDC(m_hWnd)); hBitmap = CreateCompatibleBitmap(::GetDC(m_hWnd),75,75); SelectObject(desDC,(HBITMAP)hBitmap); //copies source DC to memory DC resulting in a copy of _hbmp in hBitmap BitBlt(desDC,0,0,75,75,srcDC,0,0,SRCCOPY); DeleteDC(srcDC); DeleteDC(desDC); But if you are converting a icon to a bitmap the same code as above does not work /*for icon*/ //loading icon HICON _hbmp = LoadIcon(NULL,IDI_HAND); //creating a source memory DC and selecting a bitmap in it HDC srcDC = CreateCompatibleDC(::GetDC(m_hWnd)); SelectObject(srcDC,(HICON)_hbmp); //creating a destination memory DC and selecting a memory bitmap to it HDC desDC = CreateCompatibleDC(::GetDC(m_hWnd)); hBitmap = CreateCompatibleBitmap(::GetDC(m_hWnd),75,75); SelectObject(desDC,(HBITMAP)hBitmap); //copies source DC to memory DC resulting in a copy of _hbmp in hBitmap BitBlt(desDC,0,0,75,75,srcDC,0,0,SRCCOPY); DeleteDC(srcDC); DeleteDC(desDC); Any comment or help shall be highly appreciated. HBITMAP BitmapFromIcon(HICON hIcon) { HDC hDC = CreateCompatibleDC(NULL); HBITMAP hBitmap = CreateCompatibleBitmap(hDC, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); HBITMAP hOldBitmap = (HBITMAP)SelectObject(hDC, hBitmap); DrawIcon(hDC, 0, 0, hIcon); SelectObject(hDC, hOldBitmap); DeleteDC(hDC); return hBitmap; }
Icon to Bitmap Conversion【zz】
最新推荐文章于 2021-09-02 19:25:25 发布