/* Handles the event related to an image having been taken and waiting for processing. */ private void OnImageReadyEventCallback() { /* Acquire the image from the image provider. Only show the latest image. The camera may acquire images faster than images can be displayed*/ ImageProvider.Image image = m_imageProvider.GetLatestImage(); /* Check if the image has been removed in the meantime. */ if (image != null) { /* Check if the image is compatible with the currently used bitmap. */ if (BitmapFactory.IsCompatible(m_bitmap, image.Width, image.Height, image.Color)) { /* Update the bitmap with the image data. */ BitmapFactory.UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); Finish = true; } else /* A new bitmap is required. */ { BitmapFactory.CreateBitmap(out m_bitmap, image.Width, image.Height, image.Color); BitmapFactory.UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); Finish = true; } /* The processing of the image is done. Release the image buffer. */ m_imageProvider.ReleaseImage(); /* The buffer can be used for the next image grabs. */ } }
/* Handles the event related to an image having been taken and waiting for processing. */ private void OnImageReadyEventCallback() { try { lock (sny_Obj) { //bGrabDone = false; System.Threading.Thread.Sleep(3); /* Acquire the image from the image provider. Only show the latest image. The camera may acquire images faster than images can be displayed*/ ImageProvider.Image image = m_imageProvider.GetLatestImage(); /* Check if the image has been removed in the meantime. */ if (image != null) { mhalcon_image2.GenEmptyObj(); mhalcon_image1.GenEmptyObj(); if (IsCompatible(m_bitmap, image.Width, image.Height, image.Color)) { mhalcon_image2 = UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); mhalcon_image1 = UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); // mCGigecamera.GenertateGrayBitmap(mhalcon_image, out mm_bitmap); /* To show the new image, request the display control to update itself. */ //pictureBox1.Refresh(); } else { CreateBitmap(out m_bitmap, image.Width, image.Height, image.Color); mhalcon_image2 = UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); mhalcon_image1 = UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); } ImgHeight = image.Height; ImgWidth = image.Width; /* The processing of the image is done. Release the image buffer. */ m_imageProvider.ReleaseImage(); //BitmapData bmpData = m_bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); /* Get the pointer to the bitmap's buffer. */ //IntPtr ptrBmp = bmpData.Scan0; OnImageReadyEvent(); } while (!bGrabDone) { Thread.Sleep(5); } Thread.Sleep(10); } } catch (Exception) { //ShowException(e, m_imageProvider.GetLastErrorMessage()); } }
/* Handles the event related to an image having been taken and waiting for processing. */ private void OnImageReadyEventCallback() { if (InvokeRequired) { /* If called from a different thread, we must use the Invoke method to marshal the call to the proper thread. */ BeginInvoke(new ImageProvider.ImageReadyEventHandler(OnImageReadyEventCallback)); return; } try { /* Acquire the image from the image provider. Only show the latest image. The camera may acquire images faster than images can be displayed*/ ImageProvider.Image image = m_imageProvider.GetLatestImage(); /* Check if the image has been removed in the meantime. */ if (image != null) { /* Check if the image is compatible with the currently used bitmap. */ if (BitmapFactory.IsCompatible(m_bitmap, image.Width, image.Height, image.Color)) { /* Update the bitmap with the image data. */ BitmapFactory.UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); /* To show the new image, request the display control to update itself. */ pictureBox.Refresh(); } else /* A new bitmap is required. */ { BitmapFactory.CreateBitmap(out m_bitmap, image.Width, image.Height, image.Color); BitmapFactory.UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); /* We have to dispose the bitmap after assigning the new one to the display control. */ Bitmap bitmap = pictureBox.Image as Bitmap; /* Provide the display control with the new bitmap. This action automatically updates the display. */ pictureBox.Image = m_bitmap; if (bitmap != null) { /* Dispose the bitmap. */ bitmap.Dispose(); } } /* The processing of the image is done. Release the image buffer. */ m_imageProvider.ReleaseImage(); /* The buffer can be used for the next image grabs. */ } } catch (Exception e) { ShowException(e, m_imageProvider.GetLastErrorMessage()); } }
/// <summary> /// 影像擷取完成通知 /// </summary> private void OnImageReadyEventCallback() { try { /* Acquire the image from the image provider. Only show the latest image. The camera may acquire images faster than images can be displayed*/ ImageProvider.Image image = m_imageProvider.GetLatestImage(); /* Check if the image has been removed in the meantime. */ if (image != null) { //利用 GC Handle , 釘住記憶體不讓釋放,取得該記憶體位址 GCHandle pinnedArray = GCHandle.Alloc(image.Buffer, GCHandleType.Pinned); IntPtr pointer = pinnedArray.AddrOfPinnedObject(); try { //'byte', 'complex', 'cyclic', 'direction', 'int1', 'int2', 'int4', 'int8', 'real', 'uint2' var imgType = "byte"; HImage img = new HImage(imgType, image.Width, image.Height, pointer); if (GrabImageChanged != null) { GrabImageChanged(m_imageProvider , new System.ComponentModel.ProgressChangedEventArgs(1, img)); } } catch (Exception ex) { errorNotify(ex); } finally { //用完要釋放,否則該記憶體不會被回收 pinnedArray.Free(); } /* The processing of the image is done. Release the image buffer. */ m_imageProvider.ReleaseImage(); /* The buffer can be used for the next image grabs. */ } } catch (Exception e) { OnGrabErrorEventCallback(e, m_imageProvider.GetLastErrorMessage()); } }
private void imageProvider_ImageReadyEvent() { // Consume the Pylon queue (no copy). ImageProvider.Image pylonImage = imageProvider.GetLatestImage(); if (pylonImage == null) { return; } ComputeDataRate(pylonImage.Buffer.Length); if (FrameProduced != null) { FrameProduced(this, new FrameProducedEventArgs(pylonImage.Buffer, pylonImage.Buffer.Length)); } imageProvider.ReleaseImage(); }
private void imageProvider_ImageReadyEvent() { ImageProvider.Image pylonImage = imageProvider.GetLatestImage(); if (pylonImage == null) { waitHandle.Set(); return; } image = null; BitmapFactory.CreateBitmap(out image, pylonImage.Width, pylonImage.Height, pylonImage.Color); BitmapFactory.UpdateBitmap(image, pylonImage.Buffer, pylonImage.Width, pylonImage.Height, pylonImage.Color); imageProvider.ReleaseImage(); if (image != null) { int bufferSize = ImageFormatHelper.ComputeBufferSize(image.Width, image.Height, Kinovea.Services.ImageFormat.RGB24); imageDescriptor = new ImageDescriptor(Kinovea.Services.ImageFormat.RGB24, image.Width, image.Height, true, bufferSize); } waitHandle.Set(); }
private void imageProvider_ImageReadyEvent() { // Consume the Pylon queue (no copy). ImageProvider.Image pylonImage = imageProvider.GetLatestImage(); if (pylonImage == null) { return; } if (finishline.Enabled) { bool flush = finishline.Consolidate(pylonImage.Buffer); imageProvider.ReleaseImage(); if (flush) { ComputeDataRate(finishline.BufferOutput.Length); if (FrameProduced != null) { FrameProduced(this, new FrameProducedEventArgs(finishline.BufferOutput, finishline.BufferOutput.Length)); } } } else { ComputeDataRate(pylonImage.Buffer.Length); if (FrameProduced != null) { FrameProduced(this, new FrameProducedEventArgs(pylonImage.Buffer, pylonImage.Buffer.Length)); } imageProvider.ReleaseImage(); } }
/// <summary> /// Handles buffer updating from Managed Camera. /// </summary> public void HandleBufferUpdate(ImageProvider imageProvider) { image = imageProvider.GetLatestImage(); var ImageObject = _buffer [_bufferIndex]; if (image != null) { if (BitmapFactory.IsCompatible(ImageObject, image.Width, image.Height, image.Color)) { BitmapFactory.UpdateBitmap(ImageObject, image.Buffer, image.Width, image.Height, image.Color); } else { BitmapFactory.CreateBitmap(out Bitmap b, image.Width, image.Height, image.Color); BitmapFactory.UpdateBitmap(b, image.Buffer, image.Width, image.Height, image.Color); _buffer [_bufferIndex] = b; /*BitmapFactory.CreateBitmap (out Bitmap bitmap, image.Width, image.Height, image.Color); * BitmapFactory.UpdateBitmap (bitmap, image.Buffer, image.Width, image.Height, image.Color); */ //pictureBox.InvokeSet (bitmap); } _bufferIndex++; if (_bufferIndex >= _buffer.Length) { _bufferIndex = 0; } imageProvider.ReleaseImage(); // First check for preview saving, then call the function because: // Function increases the FPS Counter for next calls. if (!onPreviewSaving) { if (master.ShouldDrawOnBufferUpdate()) { var pictureIndex = _bufferIndex - 1; if (pictureIndex < 0) { pictureIndex = _buffer.Length - 1; } DrawPreviewImage(_buffer [pictureIndex]); } } /*if (FpsLimit > 1 && !project.Started && !onPreviewSaving) { * * fpsCounter++; * * if (fpsCounter >= FpsLimit) { * * OnPreviewImageReadyHandler (); * * fpsCounter = 0; * * } * } * else if (FpsLimit > 0 && !project.Started && !onPreviewSaving) { * * OnPreviewImageReadyHandler (); * * }*/ } }