Exemplo n.º 1
0
        private void replayButton_Click(object sender, EventArgs e)
        {
            // Here we have access to the stored images! Lets show them in an image window!!
            //Create a replay window
            if (myCamera != null && !myCamera.IsAsyncImageRecordingRunning && (myCamera.TotalAsyncImagesRecordedCount > 0))
            {
                IntPtr WindowHandle = IntPtr.Zero;

                // Try to read get the maximum width and height by looking for "SensorWidth" and "SensorHeight"
                Int32 Width      = 0;
                Int32 Height     = 0;
                CNode WidthNode  = myCamera.GetNode("Width");
                CNode HeightNode = myCamera.GetNode("Height");

                Width  = Convert.ToInt32(WidthNode.Max);
                Height = Convert.ToInt32(HeightNode.Max);

                IntPtr nodeHandle;

                uint BytesPerPixel = 4;
                if (Jai_FactoryWrapper.J_Camera_GetNodeByName(myCamera.CameraHandle, "PixelFormat", out nodeHandle) == Jai_FactoryWrapper.EFactoryError.Success)
                {
                    Int64 value = 0;
                    if (Jai_FactoryWrapper.J_Node_GetValueInt64(nodeHandle, false, ref value) == Jai_FactoryWrapper.EFactoryError.Success)
                    {
                        Jai_FactoryWrapper.EPixelFormatType pixeltype = (Jai_FactoryWrapper.EPixelFormatType)value;
                        BytesPerPixel = Jai_FactoryWrapper.GetPixelTypeMemorySize(pixeltype);
                    }
                }

                Jai_FactoryWrapper.SIZE maxSize = new Jai_FactoryWrapper.SIZE(Width, Height);

                Jai_FactoryWrapper.EFactoryError error = Jai_FactoryWrapper.EFactoryError.Success;

                // Calculate the size of the window rect to display the images
                int RectWidth  = 0;
                int RectHeight = 0;

                Jai_FactoryWrapper.RECT frameRect = new Jai_FactoryWrapper.RECT(0, 0, 100, 100);;

                // Does the image fit in width?
                if ((Width + 2 * System.Windows.Forms.SystemInformation.Border3DSize.Width) > System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width)
                {
                    RectWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - 2 * System.Windows.Forms.SystemInformation.Border3DSize.Width;
                }
                else
                {
                    RectWidth = Width;
                }

                // Does the image fit in Height?
                if ((Height + System.Windows.Forms.SystemInformation.Border3DSize.Height + System.Windows.Forms.SystemInformation.CaptionHeight) > System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height)
                {
                    RectHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - System.Windows.Forms.SystemInformation.Border3DSize.Height - System.Windows.Forms.SystemInformation.CaptionHeight;
                }
                else
                {
                    RectHeight = Height;
                }

                frameRect = new Jai_FactoryWrapper.RECT(0, 0, RectWidth, RectHeight);

                // Open the replay view
                error = Jai_FactoryWrapper.J_Image_OpenViewWindowEx(Jai_FactoryWrapper.EIVWWindowType.OverlappedStretch, "Replay", ref frameRect, ref maxSize, IntPtr.Zero, out WindowHandle);

                if (WindowHandle != IntPtr.Zero)
                {
                    List <Jai_FactoryWrapper.ImageInfo> imageList = myCamera.GetAsyncRecordedImages();
                    if (imageList != null && (imageList.Count > 0))
                    {
                        for (int index = 0; index < myCamera.TotalAsyncImagesRecordedCount; index++)
                        {
                            Jai_FactoryWrapper.ImageInfo ii = imageList[index];
                            Jai_FactoryWrapper.J_Image_SetViewWindowTitle(WindowHandle, "Replay (" + index.ToString() + "/" + myCamera.TotalAsyncImagesRecordedCount.ToString() + ")");
                            Jai_FactoryWrapper.J_Image_ShowImage(WindowHandle, ref ii, 4096, 4096, 4096);
                            Application.DoEvents();
                            //Thread.Sleep(10);
                            Delay(10);
                        }
                    }

                    Jai_FactoryWrapper.J_Image_CloseViewWindow(WindowHandle);
                }
            }
        }