VC2005中将Picture控件显示图片保存为BMP,JPG等格式

1.在stdafx.h头文件中加入

  #include <atlimage.h>

2.保存图片

  方法一:  

 
  
  HBITMAP hBitmap = NULL;
// 创建位图段
BITMAPINFO bmi;
LPBYTE pBits;
ZeroMemory(
& bmi, sizeof (bmi));
// m_bmpShow为Picture Control控件变量名称
CDC * pShowDC = m_bmpShow.GetDC();

// 获取Picture Control控件的宽度和高度
// CRect m_rcShow
m_bmpShow.GetWindowRect( & m_rcShow);

bmi.bmiHeader.biSize
= sizeof (BITMAPINFOHEADER);
bmi.bmiHeader.biWidth
= m_rcShow.Width();
bmi.bmiHeader.biHeight
= m_rcShow.Height();
bmi.bmiHeader.biPlanes
= 1 ;
bmi.bmiHeader.biBitCount
= 24 ;
bmi.bmiHeader.biCompression
= BI_RGB;
hBitmap
= CreateDIBSection(pShowDC -> m_hDC, & bmi,DIB_RGB_COLORS,( void   ** ) & pBits, 0 , 0 );
// 创建兼容dc并选择位图段
CDC dcMem;
dcMem.CreateCompatibleDC(pShowDC);
dcMem.SelectObject(hBitmap);
dcMem.BitBlt(
0 , 0 ,m_rcShow.Width(),m_rcShow.Height(),pShowDC, 0 , 0 ,SRCCOPY);
m_bmpShow.ReleaseDC(pShowDC);
if ( hBitmap )
{
CImage img;
img.Attach(hBitmap);
img.Save(_T(
" f:\\1.bmp " ));
   img.Save(_T(
" f:\\1.jpg " ));
  // 其它文件格式同理
DeleteObject(hBitmap);
AfxMessageBox(_T(
" OK!! " ));
}

 

      方法二:

 

 
  
// m_bmpShow为Picture Control控件变量名称
CDC * pdc = m_bmpShow.GetDC();
CImage imag;
// 获取Picture Control控件的宽度和高度
CRect rcClient;
m_bmpShow.GetWindowRect(
& rcClient);
imag.Create(rcClient.Width(),rcClient.Height(),
32 );

::BitBlt(imag.GetDC(),
0 , 0 ,rcClient.Width(),rcClient.Height(),pdc -> m_hDC, 0 , 0 ,SRCCOPY);

imag.Save(_T(
" f:\\2.bmp " ));
imag.Save(_T(
" f:\\21.jpg " ));
ReleaseDC(pdc);
imag.ReleaseDC();
AfxMessageBox(_T(
" OK! " ));

 

参考:http://blog.sina.com.cn/s/blog_56e19aa70100c59k.html

   http://blog.sina.com.cn/s/blog_56e19aa70100c5a0.html

 

 

转载于:https://www.cnblogs.com/cjyang/archive/2011/01/04/1925571.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值