Icon to Bitmap Conversion【zz】

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; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值