Ejemplo n.º 1
0
        private void DrawPreview()
        {
            try
            {
                ImageCaptureInfo copy = imageCaptureInfo;
                copy.captureSizeX = previewPictureBox.Width;
                copy.captureSizeY = previewPictureBox.Height;

                //Show something in the preview
                previewImage = CaptureImageFullPreview(ref copy);
                float crop_size_x = copy.actual_crop_size_x;
                float crop_size_y = copy.actual_crop_size_y;

                lastFullCapture = previewImage;
                //Draw selection rectangle
                DrawCaptureRectangleBitmap();

                //Compute image crop coordinates according to selection rectangle

                //Get raw image size from imageCaptureInfo.actual_crop_size to compute scaling between raw and rectangle coordinates

                //Console.WriteLine("SIZE X: {0}, SIZE Y: {1}", imageCaptureInfo.actual_crop_size_x, imageCaptureInfo.actual_crop_size_y);

                imageCaptureInfo.crop_coordinate_left   = selectionRectanglePreviewBox.Left * (crop_size_x / previewPictureBox.Width);
                imageCaptureInfo.crop_coordinate_right  = selectionRectanglePreviewBox.Right * (crop_size_x / previewPictureBox.Width);
                imageCaptureInfo.crop_coordinate_top    = selectionRectanglePreviewBox.Top * (crop_size_y / previewPictureBox.Height);
                imageCaptureInfo.crop_coordinate_bottom = selectionRectanglePreviewBox.Bottom * (crop_size_y / previewPictureBox.Height);

                copy.crop_coordinate_left   = selectionRectanglePreviewBox.Left * (crop_size_x / previewPictureBox.Width);
                copy.crop_coordinate_right  = selectionRectanglePreviewBox.Right * (crop_size_x / previewPictureBox.Width);
                copy.crop_coordinate_top    = selectionRectanglePreviewBox.Top * (crop_size_y / previewPictureBox.Height);
                copy.crop_coordinate_bottom = selectionRectanglePreviewBox.Bottom * (crop_size_y / previewPictureBox.Height);

                Bitmap full_cropped_capture = CaptureImageFullPreview(ref copy, useCrop: true);
                croppedPreviewPictureBox.Image = full_cropped_capture;
                lastFullCroppedCapture         = full_cropped_capture;

                copy.captureSizeX = captureSize.Width;
                copy.captureSizeY = captureSize.Height;

                //Show matching bins for preview
                var capture = CaptureImage();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.ToString());
            }
        }
Ejemplo n.º 2
0
        private void initImageCaptureInfo()
        {
            imageCaptureInfo = new ImageCaptureInfo();

            selectionTopLeft             = new Point(0, 0);
            selectionBottomRight         = new Point(previewPictureBox.Width, previewPictureBox.Height);
            selectionRectanglePreviewBox = new Rectangle(selectionTopLeft.X, selectionTopLeft.Y, selectionBottomRight.X - selectionTopLeft.X, selectionBottomRight.Y - selectionTopLeft.Y);

            imageCaptureInfo.featureVectorResolutionX = featureVectorResolutionX;
            imageCaptureInfo.featureVectorResolutionY = featureVectorResolutionY;
            imageCaptureInfo.captureSizeX             = captureSize.Width;
            imageCaptureInfo.captureSizeY             = captureSize.Height;
            imageCaptureInfo.resizeSizeXEng           = resizeSizeEng.Width;
            imageCaptureInfo.resizeSizeYEng           = resizeSizeEng.Height;
            imageCaptureInfo.resizeSizeXJpn           = resizeSizeJpn.Width;
            imageCaptureInfo.resizeSizeYJpn           = resizeSizeJpn.Height;
            imageCaptureInfo.resizeState        = ResizeState.ENG;
            imageCaptureInfo.cropOffsetX        = cropOffsetX;
            imageCaptureInfo.cropOffsetY        = cropOffsetY;
            imageCaptureInfo.captureAspectRatio = captureAspectRatioX / captureAspectRatioY;
        }
Ejemplo n.º 3
0
        public Bitmap CaptureImageFullPreview(ref ImageCaptureInfo imageCaptureInfo, bool useCrop = false)
        {
            Bitmap b = new Bitmap(1, 1);

            //Full screen capture
            if (processCaptureIndex < 0)
            {
                Screen    selected_screen = Screen.AllScreens[-processCaptureIndex - 1];
                Rectangle screenRect      = selected_screen.Bounds;

                screenRect.Width  = (int)(screenRect.Width * scalingValueFloat);
                screenRect.Height = (int)(screenRect.Height * scalingValueFloat);

                Point screenCenter = new Point((int)(screenRect.Width / 2.0f), (int)(screenRect.Height / 2.0f));

                if (useCrop)
                {
                    //Change size according to selected crop
                    screenRect.Width  = (int)(imageCaptureInfo.crop_coordinate_right - imageCaptureInfo.crop_coordinate_left);
                    screenRect.Height = (int)(imageCaptureInfo.crop_coordinate_bottom - imageCaptureInfo.crop_coordinate_top);
                }

                //Compute crop coordinates and width/ height based on resoution
                ImageCapture.SizeAdjustedCropAndOffset(screenRect.Width, screenRect.Height, ref imageCaptureInfo);

                imageCaptureInfo.actual_crop_size_x = 2 * imageCaptureInfo.center_of_frame_x;
                imageCaptureInfo.actual_crop_size_y = 2 * imageCaptureInfo.center_of_frame_y;

                if (useCrop)
                {
                    //Adjust for crop offset
                    imageCaptureInfo.center_of_frame_x += imageCaptureInfo.crop_coordinate_left;
                    imageCaptureInfo.center_of_frame_y += imageCaptureInfo.crop_coordinate_top;
                }

                //Adjust for selected screen offset
                imageCaptureInfo.center_of_frame_x += selected_screen.Bounds.X;
                imageCaptureInfo.center_of_frame_y += selected_screen.Bounds.Y;

                imageCaptureInfo.actual_offset_x = 0;
                imageCaptureInfo.actual_offset_y = 0;

                b = ImageCapture.CaptureFromDisplay(ref imageCaptureInfo);

                imageCaptureInfo.actual_offset_x = cropOffsetX;
                imageCaptureInfo.actual_offset_y = cropOffsetY;
            }
            else
            {
                IntPtr handle = new IntPtr(0);

                if (processCaptureIndex >= processList.Length)
                {
                    return(b);
                }

                if (processCaptureIndex != -1)
                {
                    handle = processList[processCaptureIndex].MainWindowHandle;
                }
                //Capture from specific process
                processList[processCaptureIndex].Refresh();
                if ((int)handle == 0)
                {
                    return(b);
                }

                b = ImageCapture.PrintWindow(handle, ref imageCaptureInfo, full: true, useCrop: useCrop, scalingValueFloat: scalingValueFloat);
            }

            return(b);
        }
Ejemplo n.º 4
0
        public Bitmap CaptureImagePostLoad()
        {
            ImageCaptureInfo imageCaptureInfo = this.imageCaptureInfo;

            imageCaptureInfo.cropOffsetX    = 500.0f;
            imageCaptureInfo.cropOffsetY    = -420.0f;
            imageCaptureInfo.captureSizeX   = 400;
            imageCaptureInfo.captureSizeY   = 200;
            imageCaptureInfo.resizeSizeXEng = 100;
            imageCaptureInfo.resizeSizeYEng = 50;

            Bitmap b = new Bitmap(1, 1);

            //Full screen capture
            if (processCaptureIndex < 0)
            {
                Screen    selected_screen = Screen.AllScreens[-processCaptureIndex - 1];
                Rectangle screenRect      = selected_screen.Bounds;

                screenRect.Width  = (int)(screenRect.Width * scalingValueFloat);
                screenRect.Height = (int)(screenRect.Height * scalingValueFloat);

                Point screenCenter = new Point(screenRect.Width / 2, screenRect.Height / 2);

                //Change size according to selected crop
                screenRect.Width  = (int)(imageCaptureInfo.crop_coordinate_right - imageCaptureInfo.crop_coordinate_left);
                screenRect.Height = (int)(imageCaptureInfo.crop_coordinate_bottom - imageCaptureInfo.crop_coordinate_top);

                //Compute crop coordinates and width/ height based on resolution
                ImageCapture.SizeAdjustedCropAndOffset(screenRect.Width, screenRect.Height, ref imageCaptureInfo);

                //Adjust for crop offset
                imageCaptureInfo.center_of_frame_x += imageCaptureInfo.crop_coordinate_left;
                imageCaptureInfo.center_of_frame_y += imageCaptureInfo.crop_coordinate_top;

                //Adjust for selected screen offset
                imageCaptureInfo.center_of_frame_x += selected_screen.Bounds.X;
                imageCaptureInfo.center_of_frame_y += selected_screen.Bounds.Y;

                b = ImageCapture.CaptureFromDisplay(ref imageCaptureInfo, useResize: true);
            }
            else
            {
                IntPtr handle = new IntPtr(0);

                if (processCaptureIndex >= processList.Length)
                {
                    return(b);
                }

                if (processCaptureIndex != -1)
                {
                    handle = processList[processCaptureIndex].MainWindowHandle;
                }
                //Capture from specific process
                processList[processCaptureIndex].Refresh();
                if ((int)handle == 0)
                {
                    return(b);
                }

                b = ImageCapture.PrintWindow(handle, ref imageCaptureInfo, useCrop: true, useResize: true);
            }

            return(b);
        }