将PictureControl的内容保存到BitMap文件中 [英] Save the content of PictureControl to a BitMap file
本文介绍了将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
推荐答案
看起来像是在以错误的方式发li.
Looks like you are blitting the wrong way.
MemDC.BitBlt(0,0,w,b,&cdc,0,0,SRCCOPY);
此外,您还需要进行一些清理,但也许您已经这样做了.
Also you need some cleaning up, but maybe you already do that.
尼克拉斯,
我更改了blitting,但是没有用,是的,清理工作已经进行了,但没有在示例代码中进行.
Hi Niklas,
I changed the blitting but no use, Yes the cleanup has been taken care, but not in the sample code.
这是为您提供的替代解决方案:
Here is an alternate solution for you:
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文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文