本文介绍了将PictureControl的内容保存到BitMap文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我如何保存Picture控件中存在的图像的内容,我尝试了以下代码,但无法保存正确的图像.我只得到了黑色图像.
Hi all,
How can i save the content of the image present in the Picture control, i tried the following code but not able to save correct image.i am getting only Black image.
<br />
<br />
CWnd* pWnd = GetDlgItem(IDC_PICTURE);<br />
<br />
HWND hWnd = pWnd->GetSafeHwnd();<br />
<br />
HDC hdc= ::GetDC(hWnd);<br />
<br />
cdc.Attach(hdc);<br />
<br />
MemDC.CreateCompatibleDC(&cdc);<br />
<br />
CBitmap Bmp;<br />
<br />
Bmp.CreateCompatibleBitmap(&cdc,w,b);<br />
<br />
CBitmap *pOldBitmap = MemDC.SelectObject(&Bmp);<br />
<br />
cdc.BitBlt(0,0,w,b,&MemDC,0,0,SRCCOPY);<br />
<br />
MemDC.SelectObject(pOldBitmap);<br />
<br />
CImage Image;<br />
<br />
Image.Attach((HBITMAP)Bmp.Detach());<br />
<br />
Image.Save(L"C:\\image.bmp");<br />
<br />
谢谢
Karthik
Thanks
Karthik
推荐答案
MemDC.BitBlt(0,0,w,b,&cdc,0,0,SRCCOPY);
此外,您还需要进行一些清理,但也许您已经这样做了.
Also you need some cleaning up, but maybe you already do that.
CStatic *pStatic = static_cast<CStatic*>(GetDlgItem(IDC_PICTURE));
CImage image;
image.Attach(pStatic->GetBitmap());
image.Save("C:\\image.bmp");
image.Detach();
假设您的控件中有一个位图.您可能需要验证GetBitmap()调用.
assuming you have a bitmap in your control. You might need to verify the GetBitmap() call.
这篇关于将PictureControl的内容保存到BitMap文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!