From MSDN topic Bitmap Constructor (Int32, Int32, Int32, PixelFormat, IntPtr)
:
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.
In your case, you release imgData
array immediately after Bitmap
creating. Keep this array persistent all time when Bitmap
is alive, according to the constructor requirements.