需要帮助将Cbitmap保存到文件 [英] need help in saving Cbitmap to file

查看:79
本文介绍了需要帮助将Cbitmap保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨;



这里是我从静态图片控件(IDC_STATIC)拍摄快照的代码,图像设置到内存中我可以将副本粘贴到绘图程序,我的问题是如何将此图像保存到文件中(我使用的是VC 2008),请修改我的代码来执行此操作,



谢谢





代码

hi;

here is my code to take a snapshot from static picture control (IDC_STATIC), and the image set into memory i can paste a copy to paint program, my question is how can i save this image to file (i am using VC 2008), please modify my code to do so,

thanks


the code

CDC dc;

   /* client area only */
	CRect rect;
CWnd *wnd = GetDlgItem(IDC_STATIC);
wnd->GetWindowRect(&rect);
//wnd->ScreenToClient(&rect); //optional step - see below

         HDC hdc = ::GetDC(wnd->m_hWnd);
         dc.Attach(hdc);
       

     CDC memDC;

     memDC.CreateCompatibleDC(&dc);

     CBitmap bm;
     CRect r;

      
         wnd->GetClientRect(&r);
        

     CString s;
     wnd->GetWindowText(s);

     CSize sz(r.Width(), r.Height());

     bm.CreateCompatibleBitmap(&dc, sz.cx, sz.cy);

     CBitmap * oldbm = memDC.SelectObject(&bm);

     memDC.BitBlt(0, 0, sz.cx, sz.cy, &dc, 0, 0, SRCCOPY);

     wnd->GetParent()->OpenClipboard();
     ::EmptyClipboard();
     ::SetClipboardData(CF_BITMAP, bm.m_hObject);
     CloseClipboard();

     memDC.SelectObject(oldbm);
     bm.Detach(); 

推荐答案

使用 GDI + 使其变得简单,请参阅将CBITMAP保存到文件 [ ^ ]。
Using GDI+ makes it simple, see "SAVE CBITMAP TO FILE"[^].


这篇关于需要帮助将Cbitmap保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆