CNET中国旗舰网站

ZDNet China | CNET科技资讯网 | 政府采购 | 行业网站联盟





 
标题: [讨论] C#中如何在摄像头的预览画面的时候如何画矩形(即矩形一直在视频摄像时候一直存在)
liushuimong
论坛游民




UID 324225
精华 0
积分 21
帖子 1
威望 10
ZD币 17 元
阅读权限 20
注册 2008-5-4
状态 离线
  楼主
发表于 2008-5-4 20:44  资料  个人空间  短消息  加为好友 
开发者在线

C#中如何在摄像头的预览画面的时候如何画矩形(即矩形一直在视频摄像时候一直存在)

C#中如何在摄像头的预览画面的时候画矩形,用于截取自己想要的那部分图片? (注:视频在摄像的时候,那个矩形一直在上面,目的就是用于截取图用的!)




顶部
zhang_daqian
特级会员
Rank: 3Rank: 3



UID 280439
精华 0
积分 986
帖子 52
威望 320
ZD币 91 元
阅读权限 70
注册 2007-12-25
状态 离线
  沙发
发表于 2008-5-7 08:54  资料  个人空间  短消息  加为好友 
using   System.Drawing;   
  using   System.Windows.Forms;   
   
  class   Test   :   Form   
  {   
      Rectangle   r   =   Rectangle.Empty;   
   
      protected   override   void   OnMouseDown(MouseEventArgs   e)   
      {   
          r.X   =   e.X;   
          r.Y   =   e.Y;   
      }   
   
      protected   override   void   OnMouseUp(MouseEventArgs   e)   
      {   
          if(e.X   <   r.X)   
          {   
              r.Width   =   r.X   -   e.X;   
              r.X           =   e.X;   
          }   
          else   
          {   
              r.Width   =   e.X   -   r.X;   
          }   
   
          if(e.Y   <   r.Y)   
          {   
              r.Height   =   r.Y   -   e.Y;   
              r.Y             =   e.Y;   
          }   
          else   
          {   
              r.Height   =   e.Y   -   r.Y;   
          }   
          Invalidate(new   Rectangle(r.X,   r.Y,   r.Width+1,   r.Height+1));   
      }   
   
      protected   override   void   OnPaint(PaintEventArgs   e)   
      {   
          base.OnPaint(e);   
          e.Graphics.DrawRectangle(new   Pen(Color.Blue,   0),   r);   
      }   
   
      static   void   Main()   
      {   
          Application.Run(new   Test());   
      }   
  }   
  
Top


  using   System.Drawing;   
  using   System.Windows.Forms;   
   
  class   Test   :   Form   
  {   
      int   x0,   y0,   x1,   y1;   
      Rectangle   r   =   Rectangle.Empty;   
   
      protected   override   void   OnMouseDown(MouseEventArgs   e)   
      {   
          x0   =   e.X;   
          y0   =   e.Y;   
      }   
   
      protected   override   void   OnMouseMove(MouseEventArgs   e)   
      {   
          x1   =   e.X;   
          y1   =   e.Y;   
          Invalidate();   
      }   
   
      protected   override   void   OnPaint(PaintEventArgs   e)   
      {   
          base.OnPaint(e);   
          if   (x0   <   x1)   {   r.X   =   x0;   r.Width     =   x1   -   x0;   }   
          else                   {   r.X   =   x1;   r.Width     =   x0   -   x1;   }   
          if   (y0   <   y1)   {   r.Y   =   y0;   r.Height   =   y1   -   y0;   }   
          else                   {   r.Y   =   y1;   r.Height   =   y0   -   y1;   }   
          e.Graphics.DrawRectangle(new   Pen(Color.Blue,   0),   r);   
      }   
   
      static   void   Main()   
      {   
          Application.Run(new   Test());   
      }   
  }




顶部
热点频道推荐: C/S开发| 数据库| WEB开发| 嵌入式| 项目管理|
 



当前时区 GMT+8, 现在时间是 2009-7-4 07:22

  Powered by Discuz! 5.5.0 © 2001-2007 Comsenz Inc.
Processed in 0.062274 second(s), 4/3 queries

清除 Cookies - 联系我们 - ZDNetChina中文社区 - 无图版