i have a project that captures images by basler camera and for this i have a onimagegrabbed Function that grabs image. while running my project in any cpu it i did not getting any error. but when i turned to x86 , project runs but after 2 or 3 seconds I am getting exception message " system.argumentexception parameter is not valid. at system.drawing.bitmap..ctor(int32 width, int32 height, pixelformat format) ."
Screenshot-65 — ImgBB[
^]
also showing this message in console tab
Exception thrown: 'System.ArgumentException' in System.Drawing.dll
What I have tried:
private void OnImageGrabbed(object sender, ImageGrabbedEventArgs e)
{
bool invokeRequired = base.InvokeRequired;
if (invokeRequired)
{
base.BeginInvoke(new EventHandler<ImageGrabbedEventArgs>(this.OnImageGrabbed), new object[]
{
sender,
e.Clone()
});
}
else
{
try
{
this.grabResult = e.GrabResult;
bool isValid = this.grabResult.IsValid;
if (isValid)
{
bool flag = !this.stopWatch.IsRunning || this.stopWatch.ElapsedMilliseconds > 33L;
if (flag)
{
this.stopWatch.Restart();
Bitmap bitmap = new Bitmap(this.grabResult.Width, this.grabResult.Height, PixelFormat.Format32bppRgb);
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
this.converter.OutputPixelFormat = PixelType.BGRA8packed;
IntPtr scan = bitmapData.Scan0;
this.converter.Convert(scan, (long)(bitmapData.Stride * bitmap.Height), this.grabResult);
bitmap.UnlockBits(bitmapData);
object obj = this.lockObject;
lock (obj)
{
Bitmap bitmap2 = this.DisplayWindow.Image as Bitmap;
bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
this.gb = this.CreateNonIndexedImage(bitmap);
this.DisplayWindow.Image = bitmap;
bool flag3 = bitmap2 != null;
if (flag3)
{
bitmap2.Dispose();
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
e.DisposeGrabResultIfClone();
}
}
}
the line:150 is " Bitmap bitmap = new Bitmap(this.grabResult.Width, this.grabResult.Height, PixelFormat.Format32bppRgb);"