Hi Sir,
I am developing a image processing project in which captured image is first converted into GrayScale after that processing on image with color according to dark spot.
First of all i am converting captured image into grayscale where I wrote following code and got an error.
private void cmb_cameras_SelectedIndexChanged(object sender, EventArgs e)
{
FinalVideoSource = new VideoCaptureDevice(VideoCaptureDevices[cmb_cameras.SelectedIndex].MonikerString);
FinalVideoSource.NewFrame += new NewFrameEventHandler(FinalVideoSource_NewFrame);
FinalVideoSource.Start();
}
void FinalVideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
try
{
LiveImage = (Bitmap)eventArgs.Frame.Clone();
Bitmap newBitmap = new Bitmap(LiveImage.Width, LiveImage.Height);
Graphics g = Graphics.FromImage(newBitmap);
ColorMatrix colorMatrix = new ColorMatrix(
new float[][]
{
new float[] {.3f, .3f, .3f, 0, 0},
new float[] {.59f, .59f, .59f, 0, 0},
new float[] {.11f, .11f, .11f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
});
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(colorMatrix);
g.DrawImage(LiveImage, new Rectangle(0, 0, LiveImage.Width, LiveImage.Height),
0, 0, LiveImage.Width, LiveImage.Height, GraphicsUnit.Pixel, attributes);
PB_LiveImage.Image = newBitmap;
g.Dispose();
attributes.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
I am using Aforge to captured image.
The error I face:
System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
at FootPrintMapping.MainScreen.FinalVideoSource_NewFrame(Object sender, NewFrameEventArgs eventArgs) in MainScreen.cs:line 59