// Occurs when an image has been acquired and is ready to be processed. private void OnImageGrabbed(Object sender, ImageGrabbedEventArgs e) { try { // Acquire the image from the camera. Only show the latest image. The camera may acquire images faster than the images can be displayed. // Get the grab result. IGrabResult grabResult = e.GrabResult; // Check if the image can be displayed. if (grabResult.GrabSucceeded) { Bitmap bitmap = new Bitmap(grabResult.Width, grabResult.Height, PixelFormat.Format32bppRgb); // Lock the bits of the bitmap. BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); // Place the pointer to the buffer of the bitmap. converter.OutputPixelFormat = PixelType.BGRA8packed; IntPtr ptrBmp = bmpData.Scan0; converter.Convert(ptrBmp, bmpData.Stride * bitmap.Height, grabResult); bitmap.UnlockBits(bmpData); //UI thread에 접근하기 위해 dispatcher 사용 dispatcher.BeginInvoke((Action)(() => { CameraImage = ConvertImage.BitmapToImageSource(bitmap); })); FrameRate = Param.ResultingFrameRateAbs; if (IsImageSaveAuto == true) { Image_Save(); } /* * dispatcher.BeginInvoke((Action)(() => * { * CameraImageComplete(); * })); */ } } catch (Exception exception) { Log.Set(string.Format("Exception: {0}", exception.Message)); } finally { // Dispose the grab result if needed for returning it to the grab loop. e.DisposeGrabResultIfClone(); } }