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
{
using (ImageAttributes attributes = new ImageAttributes())
{
LiveImage = (Bitmap)eventArgs.Frame.Clone();
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}
});
attributes.SetColorMatrix(colorMatrix);
g.DrawImage(
LiveImage,
new Rectangle(0, 0, LiveImage.Width, LiveImage.Height),
0, 0,
LiveImage.Width, LiveImage.Height,
GraphicsUnit.Pixel, attributes);
}
foreach (int a in IEnum_a)
{
foreach (int c in IEnum_c)
{
now_color = NewBitmap.GetPixel(c, a);
if (now_color.ToArgb() == Color.WhiteSmoke.ToArgb())
ProcessedBitmap.SetPixel(c, a, Color.Orange);
else if (now_color.ToArgb() == Color.White.ToArgb())
ProcessedBitmap.SetPixel(c, a, Color.Cyan);
else if (now_color.ToArgb() == Color.DarkGray.ToArgb())
ProcessedBitmap.SetPixel(c, a, Color.Red);
else
ProcessedBitmap.SetPixel(c, a, Color.Blue);
}
}
PB_LiveImage.Image = ProcessedBitmap;
}
catch (Exception ex)
{
MessageBox.Show("Message:\n Kindly closed the application.");
}
}
I got an error from above code that "object is currently in use elsewhere". Which object is used in elsewhere and How do I check it?