Esempio n. 1
0
        private 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);
        }