Hi,
I want to do image processing with real-time image and I’m using C#. I got to grab the image from webcam and it runs smoothly. However, I got some error when I attach with other code for image processing. I cannot run more than one time in one execution debugging.
It gives exception: “Could not grab picture. A generic error occurred in GDI+.”
I just attach one class library to do threshold process for color image that I grabbed.
This is the original class to grab the image:
--------------------------------------------------------------------------
toolBarBtnGrab.Enabled = true;
int hr;
if( sampGrabber == null )
return;
hr = sampGrabber.SetCallback( null, 0 );
int w = videoInfoHeader.BmiHeader.Width;
int h = videoInfoHeader.BmiHeader.Height;
int stride = w * 3;
GCHandle handle = GCHandle.Alloc( savedArray, GCHandleType.Pinned );
int scan0 = (int) handle.AddrOfPinnedObject();
scan0 += (h - 1) * stride;
Bitmap b = new Bitmap( w, h, -stride, PixelFormat.Format24bppRgb, (IntPtr) scan0 );
handle.Free();
savedArray = null;
Image old = pictureBox.Image;
pictureBox.Image = b;
--------------------------------------------------------------------------
and below is the code that I added after the last line of above code to call class library for threshold the image that was grabbed by above code:
--------------------------------------------------------------------------
pictureBox.Image.Save("1stImage.Jpeg", ImageFormat.Jpeg);
Bitmap bp = new Bitmap("1stImage.Jpeg");
ClassLibrary1.Class1 filter = new ClassLibrary1.Class1();
System.Drawing.Bitmap binary = filter.Binary(bp);
picClass1.Image = binary;
picClass1.Image.Save("Binary.Jpeg", ImageFormat.Jpeg);
picClass1.Width = binary.Width;
picClass1.Height = binary.Height;
--------------------------------------------------------------------------
Could any body help me please to overcome this problem. Thanks.