Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# gdi+;在图形对象上绘制图像时出现常规错误_C#_.net_Windows_Gdi+ - Fatal编程技术网

C# gdi+;在图形对象上绘制图像时出现常规错误

C# gdi+;在图形对象上绘制图像时出现常规错误,c#,.net,windows,gdi+,C#,.net,Windows,Gdi+,考虑以下在windows服务中运行的代码 Graphics g = Graphics.FromImage(printImage); for (int rows = 1; rows <= thumbRows; rows++) { for (int cols = 1; cols <= thumbColumns; cols++) { using (Image thumbImage = new Bitmap(resourceQueue.Peek())) {

考虑以下在windows服务中运行的代码

Graphics g = Graphics.FromImage(printImage);

for (int rows = 1; rows <= thumbRows; rows++) {
    for (int cols = 1; cols <= thumbColumns; cols++) {
      using (Image thumbImage = new Bitmap(resourceQueue.Peek()))
      {  
          g.DrawImage(thumbImage, targetRect, sourceRect, GraphicsUnit.Pixel);

          resourceQueue.Dequeue();
          if (resourceQueue.Count == 0) break;
      }
    }
}
Graphics g=Graphics.FromImage(printImage);

对于(int rows=1;rows最有可能是用于创建位图的流(如果是这样的话)已关闭。它们必须在位图的生命周期内保持打开状态。您可以将流复制到新的MemoryStream中,然后关闭原始流。

我们看不到带有错误的代码,它位于位图被推入队列之前创建位图的代码中。由于您非常小心使用,因此很可能会执行某些操作类似于处理内存流。当图像内存管理器需要使用本机像素数据来渲染图像时,它会爆炸。resourceQueue是一个字符串队列,包含指向它不包含图像的图像的路径。在图形对象上绘制后,可以安全地处理thumbImage,对吗?我没有猜到这个队列包含字符串.不知道为什么13是一个不吉利的数字。今天是星期五。上面的图像是否在代码中的其他任何地方使用(例如,在另一个线程中)?不,它们当时不只是用于缩小它们并将它们打印在新图像上。