Hello,
I am working on a C# application that would display live images from a camera. The problem i am facing with the below code snippet is that, i get AccessViolationException in Marshall.Copy method when running this function executed continuosly in a thread. But, this runs successfuly when run once (i get a single static image). I guess it has to do with some memory corruption issue. Any idea/suggestions on how to deal with this problem ?
private Image ByteArrayToImage(byte[] myByteArray)
{
if (myByteArray != null)
{
MemoryStream ms = new MemoryStream(myByteArray);
int Height = 504;
int Width = 664;
Bitmap bmp = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
Marshal.Copy(myByteArray, 0, bmpData.Scan0, myByteArray.Length);
bmp.UnlockBits(bmpData);
return bmp;
}
return null;
}