CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  图形处理/算法

关于DC的几个简单问题 送高分+在线等~~~

楼主nonowhy(只当我up好了,up也要up出水平)2004-09-03 13:34:52 在 VC/MFC / 图形处理/算法 提问

关于DC有几个问题一直不是很明白:  
  1   在显示一副图像(如jpg)的过程中   到底有几个dc   看有些代码在这些dc之间copy过来   copy过去的   晕~~~    
  2   所谓的内存dc和其他dc有什么区别?  
   
  3   CDC   Memdc;  
    Memdc.GetSafeHdc()得到就是内存dc???  
   
  4   CreateCompatibleDC()到底有什么意义?这段代码有什么问题:  
  void   CImageView::OnDraw(CDC*   pDC)  
  {  
  CImageDoc*   pDoc   =   GetDocument();  
  ASSERT_VALID(pDoc);  
  //   TODO:   add   draw   code   for   native   data   here  
  CMainFrame   *pImgWnd   =   (CMainFrame   *)::AfxGetMainWnd();  
  ASSERT_VALID(pImgWnd);  
                      下面三行注释掉:  
  /*  
                    CDC   Memdc;  
  Memdc.CreateCompatibleDC   (   pDC   );  
  Memdc.SelectObject   ();  
                    */  
  BITMAP   bitmap   =   pImgWnd->m_bitmap   ;  
  pDC->BitBlt   (   0   ,   0   ,   bitmap.bmWidth   ,   bitmap.bmHeight   ,   pDC   ,   0   ,0   ,   SRCCOPY);  
   
  }  
  上面代码的问题   请给讲解一下   多谢~~~  
  讲的清楚   高分给!  
   
  问题点数:50、回复次数:14Top

1 楼lanstar200(待我景天大侠斩妖除魔)回复于 2004-09-03 13:38:50 得分 0

先看看<<Windows圖形編程>>吧Top

2 楼nonowhy(只当我up好了,up也要up出水平)回复于 2004-09-03 14:07:32 得分 0

哪位可以讲解一下~~~      
  请不要来就说看什么书   那大家还问什么问题?Top

3 楼nonowhy(只当我up好了,up也要up出水平)回复于 2004-09-03 14:40:02 得分 0

大家帮忙看看下面有什么问题   运行是出现assert错误:  
  void   CImageView::OnDraw(CDC*   pDC)  
  {  
  CImageDoc*   pDoc   =   GetDocument();  
  ASSERT_VALID(pDoc);  
  //   TODO:   add   draw   code   for   native   data   here  
  CMainFrame   *pImgWnd   =   (CMainFrame   *)::AfxGetMainWnd();  
  ASSERT_VALID(pImgWnd);  
   
  CDC   Memdc;  
  Memdc.CreateCompatibleDC   (pDC);  
  CBitmap   *pMemBitmap;  
  ASSERT_VALID(&(pImgWnd->Bitmap));  
  pMemBitmap   =   Memdc.SelectObject   (   &(pImgWnd->Bitmap)   );  
                    BITMAP   bitmap   =   pImgWnd->m_bitmap   ;  
  pDC->BitBlt   (   0   ,   0   ,   bitmap.bmWidth   ,   bitmap.bmHeight   ,   &Memdc   ,   0   ,0   ,   SRCCOPY);  
   
  }Top

4 楼shenailin(sal)回复于 2004-09-03 14:45:34 得分 0

 
   
  CImageDoc*   pDoc   =   GetDocument();  
  ASSERT_VALID(pDoc);  
  //   TODO:   add   draw   code   for   native   data   here  
  CMainFrame   *pImgWnd   =   (CMainFrame   *)::AfxGetMainWnd();  
  ASSERT_VALID(pImgWnd);  
                      下面三行注释掉:  
  /*  
                    CDC   Memdc;  
  Memdc.CreateCompatibleDC   (   pDC   );  
  Memdc.SelectObject   ();  
                    */  
  //   将客户区(显示设备)的(0,0)开始的图像(宽:bitmap.bmWidth   高:bitmap.bmHeight   )copy并显示  
  pDC->BitBlt   (   0   ,   0   ,   bitmap.bmWidth   ,   bitmap.bmHeight   ,   pDC   ,   0   ,0   ,   SRCCOPY);  
  Top

5 楼nonowhy(只当我up好了,up也要up出水平)回复于 2004-09-03 14:56:37 得分 0

to:   shenailin(sal)  
   
  多谢你帮我up!   还是不知道你什么意思!Top

6 楼puhuofeie(扑火飞蛾)回复于 2004-09-03 15:59:04 得分 20

第一  
  CMainFrame   *pImgWnd   =   (CMainFrame   *)::AfxGetMainWnd();  
  ASSERT_VALID(pImgWnd);  
  这个我没用过。。  
  OnDraw里面可以这么用么?  
  OnDraw可是每次刷新都会调用的。。Top

7 楼puhuofeie(扑火飞蛾)回复于 2004-09-03 16:03:35 得分 10

关于内存dc,  
  通常是用2个,就是双缓存技术,  
  与刷新有关,  
  具体的知识还得查资料。  
  先把想画的东西画在一个dc里,这个dc只是与当前dc相兼容,  
  在内存,  
  画完了,就显示在设备dc上。  
   
  我得理解大概就是这些,再查查资料,,Top

8 楼puhuofeie(扑火飞蛾)回复于 2004-09-03 16:07:30 得分 10

CDC::CreateCompatibleDC   creates   a   memory   DC   that's   compatible   with   the   specified   device   context.   The   device   context   whose   address   you   pass   in   is   usually   a   screen   DC,   but   it   could   just   as   easily   be   a   printer   DC   if   the   image   you're   preparing   is   destined   for   a   printer   rather   than   the   screen.   Once   a   bitmap   is   selected   into   a   memory   DC,   you   can   draw   to   the   memory   DC   (and   hence   into   the   bitmap)   using   the   same   CDC   member   functions   you   use   to   draw   to   a   screen   or   printer   DC.  
   
  The   big   difference   between   drawing   to   a   memory   DC   and   drawing   to   a   screen   DC   is   that   pixels   drawn   to   a   memory   DC   aren't   displayed.   To   display   them,   you   have   to   copy   them   from   the   memory   DC   to   a   screen   DC.   Drawing   to   a   memory   DC   first   and   then   transferring   pixels   to   a   screen   DC   can   be   useful   for   replicating   the   same   image   on   the   screen   several   times.   Rather   than   draw   the   image   anew   each   time,   you   can   draw   it   once   in   a   memory   DC   and   then   transfer   the   image   to   a   screen   DC   as   many   times   as   you   want.   (Be   aware,   however,   that   many   display   adapters   will   perform   better   if   you   copy   the   image   from   the   memory   DC   to   the   screen   DC   one   time   and   then   replicate   the   image   already   present   in   the   screen   DC   as   needed.)   Bitmaps   play   an   important   role   in   the   process   because   when   a   memory   DC   is   first   created   it   contains   just   one   pixel   you   can   draw   to,   and   that   pixel   is   a   monochrome   pixel.   Selecting   a   bitmap   into   a   memory   DC   gives   you   a   larger   display   surface   to   draw   on   and   also   more   colors   to   work   with   as   long   as   the   bitmap   isn't   monochrome.  
   
  Top

9 楼nonowhy(只当我up好了,up也要up出水平)回复于 2004-09-03 16:20:57 得分 0

多谢斑竹~~~   很有帮助!Top

10 楼nonowhy(只当我up好了,up也要up出水平)回复于 2004-09-03 16:48:13 得分 0

CMainFrame   *pImgWnd   =   (CMainFrame   *)::AfxGetMainWnd();  
  ASSERT_VALID(pImgWnd);  
  --------------------------------------------------------------------------  
  pImgWnd一个局部变量   应该不影响吧~~~   通过pImgWnd把BITMAP   m_bitmap成员变量传递过来    
  这里怎么处理好啊    
  显示图片的时候还是要出现assert错误   -_-~   斑竹再帮帮忙!Top

11 楼puhuofeie(扑火飞蛾)回复于 2004-09-03 17:08:12 得分 0

你把bitmap从资源中的来,看你到底是fram的问题,还是你bitmap操作不对。。Top

12 楼nonowhy(只当我up好了,up也要up出水平)回复于 2004-09-03 21:28:45 得分 0

严重无语~~~把这里一起帖出来吧:  
  void   CMainFrame::OnFileOpen()    
  {  
  //   TODO:   Add   your   command   handler   code   here  
  LPCTSTR   lpFilter   =   "BMP文件(*.bmp)|   *.bmp   |JPG文件(*.jpg)   |   *.jpg|";  
  CFileDialog   FileDlg   (   true   ,   NULL   ,   NULL   ,     OFN_HIDEREADONLY   ,   lpFilter   ,   NULL   );  
  if   (FileDlg.DoModal()   ==   IDOK)  
  {  
  try  
  {  
  CString   strFileName   =   FileDlg.GetFileName   ();  
  HBITMAP   hBitmap;  
  hBitmap   =   (HBITMAP) LoadImage(0   ,    
      (LPCTSTR)strFileName   ,    
      IMAGE_BITMAP   ,    
      0,    
      0,  
      LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE);  
   
  //::AfxMessageBox   (strFileName);  
  m_Bitmap.Attach   (   hBitmap   );  
  m_Bitmap.GetBitmap   (   &bmp);  
  //m_Bitmap.GetObject   (sizeof(m_bmp)   ,   &m_bmp);  
  ::AfxMessageBox   ((LPCTSTR)&bmp);     //没有执行    
                                                            //无论是m_Bitmap.GetBitmap()   还是m_Bitmap.GetObject   ()都一样   怎么回事   大家帮帮忙!    
  Invalidate(   true   );  
  }  
  catch(...)  
  {  
  ::AfxMessageBox   ("error   occur");  
  }  
  }  
  }  
  Top

13 楼Mackz(在相互)回复于 2004-09-03 23:16:58 得分 5

只能说你对位图概念一塌糊涂。  
   
  对MFC概念也是一塌糊涂。  
   
  读取文件可以在CDocument里实现。  
  m_Bitmap.GetBitmap   (   &bmp);//bmp没见你声明,假设是BITMAP   bmp,怎么能用::AfxMessageBox   ((LPCTSTR)&bmp);?匪夷所思。  
  况且,得到BITMAP干什么?  
  BITMAP   bitmap   =   pImgWnd->m_bitmap   ;//匪夷所思。我想你的m_bitmap是CBitmap类型的吧?这句编译不出错?  
   
  你说“请不要来就说看什么书   那大家还问什么问题?”,可是至少先看看MSDN吧,否则,别人说了你也看不懂,难道要从基础开始上课吗?问问题还是先要自己懂一些,再来探讨疑难才有效率吧。Top

14 楼AlexSu(AlexSu)回复于 2004-09-04 13:43:50 得分 5

楼上说的对啊!兄弟,事情要靠自己做出来的,不是发一个帖子就可以把什么问题都解决了。别心浮气燥,做程序员的切记要静下心来的。斑竹的回复不错,学习ingTop

相关问题

  • 在线,简单,马上给分 ,多分!
  • 很简单的线程问题,,有分
  • 简单问题,在线送分!!!
  • HTTP的简单问题,在线放分!
  • SQL简单问题,在线给分。
  • SQL简单问题,在线给分。
  • 很简单的问题,在线给分!
  • 简单问题,在线给分!
  • 简单问题,高分,在线等待..
  • 巨简单,送分!在线等待!

关键词

  • dc
  • 内存
  • 代码
  • pimgwnd
  • bitmap
  • memdc
  • pdc
  • bmp
  • cimagedoc
  • herecmainframe

得分解答快速导航

  • 帖主:nonowhy
  • puhuofeie
  • puhuofeie
  • puhuofeie
  • Mackz
  • AlexSu

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo