GDI+ exception saving a Bitmap to a MemoryStream

后端 未结 2 982
终归单人心
终归单人心 2021-01-06 14:36

I have a problem in a Windows Forms application with Bitmap.Save failing when I save to a MemoryStream. The problem only seems to occur intermittently on one machine (so fa

相关标签:
2条回答
  • 2021-01-06 14:57

    Have you tried moving

       picture.releasePixelData(pPixels);
    

    to

       finally
       {
           memStream.Dispose();
           picture.releasePixelData(pPixels);
       }
    

    it definitely sounds like a threading issue (especially since you state that the releasePixelData could happen on a background thread). Threading issues are always the ones that only happen on one machine, and it is always on the clients machine (probably due to the fact they only have 256Megs of memory or something ridiculous and garbage collector is kicking in early, or the machine has quad core and your developer machine is dual core or something).

    0 讨论(0)
  • 2021-01-06 15:06

    The MSDN docs for that Bitmap constructor leave no doubt whatsoever:

    Remarks The caller is responsible for allocating and freeing the block of memory specified by the scan0 parameter, however, the memory should not be released until the related Bitmap is released.

    0 讨论(0)
提交回复
热议问题