System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性错误
   at System.Drawing.Image.FromHbitmap(IntPtr hbitmap, IntPtr hpalette)
   at System.Drawing.Image.FromHbitmap(IntPtr hbitmap)
   at ContextSave.ScreenShot.GetPartScreen(Point P1, Point P2, Boolean Full) in c:\ccontextsave9\contextsave\screenshot.cs:line 62
   at ContextSave.Form1.SaveGroupToDB(Boolean confirm) in c:\ccontextsave9\contextsave\form1.cs:line 301
   at ContextSave.Form1.timer_Tick(Object sender, EventArgs e) in c:\ccontextsave9\contextsave\form1.cs:line 835
   at System.Windows.Forms.Timer.OnTick(EventArgs e)
   at System.Windows.Forms.Timer.Callback(IntPtr hWnd, Int32 msg, IntPtr idEvent, IntPtr dwTime)是winform程序,不存在权限问题
程序是5秒钟截屏一次,有的时候可以,时间长了就报错。程序代码如下
Bitmap bmap = ScreenShot.GetPartScreen(new Point(0),new Point(0),true);
bmap.Save(groupName+".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
bmap.Dispose();我尝试过改为
MemoryStream ms=new MemoryStream();
bmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
System.IO.BinaryWriter bw=new BinaryWriter(ms);
FileStream fs=File.OpenWrite(groupName+".jpg");
for(int i=0;i<ms.ToArray().Length;i++)
  fs.WriteByte(ms.ToArray()[i]);
fs.Flush();
fs.Close();但是ms array的长度是以万计的,速度太慢,所以不行。
有更好的方法吗

解决方案 »

  1.   

    ...注意点别冲突就行了, 一定要注意                //Monitor.Enter(this);
                    //Monitor.Pulse(this);
     //Monitor.Exit(this);
      

  2.   

    我原来的是
    private void timer_Tick(object sender, System.EventArgs e)
    {
    this.timer.Enabled=false;
    lock(this)
    {
    this.SaveGroupToDB(false);
    }
    this.timer.Enabled=true;
    }改为
    private void timer_Tick(object sender, System.EventArgs e)
    {
    System.Threading.Monitor.Enter(this); this.SaveGroupToDB(false); System.Threading.Monitor.Exit(this);
    }还是出错......
      

  3.   

    把所有对象都关掉Close,Dispose,null等
      

  4.   

    谢谢回复bmap只有Dispose,我已经用了
    而且它是临时变量