mafei863分享 http://blog.sciencenet.cn/u/mafei863 道法自然,道即合理

博文

如果在使用GetHdc方法后使用Graphics对象,请调用ReleaseHdc方法

已有 11200 次阅读 2014-3-30 17:19 |个人分类:c#编程|系统分类:科研笔记

给你个提示: 你的两个线程同时访问了同一幅图像。 造成冲。简单的方法是在每个线程都要拥有自己的一份图像副本。分别对自己的副本进行对写操作。

你的这个问题可能不是因为没用队列造成的,但你肯定是要用队列。你发送的速度远远跟不上捕获的速度的。


 private void thDrawRectangleToShowError()

       {

           g = this.pictureBox1.CreateGraphics();

           userSetPen = new Pen(clrUserSetResultColor, 3);

           grayPen = new Pen(Color., 3);

           int i3 = 1;

           while (true)

           {

               //s++;

               //Invoke(new MethodInvoker(delegate

               //   {

               //       label3.ForeColor = Color.Red;

               //       label3.Text = "             等待检测...               ";

               //   }));

               //if(g!=null)

               //    g.Dispose();

               //try

               //{

               //    //g = this.pictureBox1.CreateGraphics();

                 

               //}catch(Exception ex)

               //{

               //    MessageBox.Show(ex.Message);

               //}

               

               for (int i = 0; i < errorCount; i++)

               {

                   index = arrErrorFuseLocation[i];

                   g.DrawRectangle(userSetPen,

                     new Rectangle(arrFeature[index].x0, arrFeature[index].y0,

                     arrFeature[index].x1 - arrFeature[index].x0,

                     arrFeature[index].y1 - arrFeature[index].y0));

                   //g.DrawRectangle(userSetPen,

                   // new Rectangle(33,33,33,33));

                   Thread.Sleep(300);

                   g.DrawRectangle(grayPen,

                     new Rectangle(arrFeature[index].x0, arrFeature[index].y0,

                     arrFeature[index].x1 - arrFeature[index].x0,

                     arrFeature[index].y1 - arrFeature[index].y0));

                   

                   Thread.Sleep(100);///!!!/////在该处增加时间,不会出现异常

                 


               }

               //grayPen.Dispose();

               //    userSetPen.Dispose();

               ////g.Dispose();

           }




https://wap.sciencenet.cn/blog-538909-780506.html

上一篇:c#-picturebox图像缩放后的保存
下一篇:在pictureBox中输出字符串---------跨线程托管访问
收藏 IP: 125.46.3.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-21 22:28

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部