paip.Image对象出现“对象当前正在其他地方使用或者GDI+中发生一般性错误的解决

paip.Image对象出现“对象当前正在其他地方使用或者GDI+中发生一般性错误的解决
作者Attilax ,  [email protected]


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




   private Image GetImage(string fileName)
        {
            Image imgr;
            byte[] bytes = File.ReadAllBytes(fileName);
            using (MemoryStream ms = new MemoryStream(bytes))
            {
              imgr=new Bitmap(   Image.FromStream(ms));
            }


            return imgr;
        }

你可能感兴趣的:(other)