コード例 #1
0
        private static Image PrepareBevel(Image image, Point[] points, int filterValue)
        {
            Bitmap       bmp = new Bitmap(image.Width, image.Height);
            Graphics     g   = Graphics.FromImage(bmp);
            GraphicsPath gp  = new GraphicsPath();

            gp.AddPolygon(points);
            g.Clear(Color.Transparent);
            g.SetClip(gp);
            g.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height));
            g.Dispose();
            ColorMatrix cm;

            switch (Engine.conf.BevelFilterType)
            {
            default:
            case FilterType.Brightness:
                cm = ColorMatrices.BrightnessFilter(filterValue);
                break;

            case FilterType.Contrast:
                cm = ColorMatrices.ContrastFilter(filterValue);
                break;

            case FilterType.Saturation:
                cm = ColorMatrices.SaturationFilter(filterValue);
                break;
            }
            bmp = ColorMatrices.ApplyColorMatrix(bmp, cm);
            Graphics g2 = Graphics.FromImage(image);

            g2.DrawImage(bmp, new Rectangle(0, 0, image.Width, image.Height));
            g2.Dispose();
            return(image);
        }
コード例 #2
0
        /// <summary>
        /// Crop shot or Selected Window captures
        /// </summary>
        /// <param name="myImage">Fullscreen image</param>
        /// <param name="windowMode">True = Selected window, False = Crop shot</param>
        public Crop(Image myImage, bool windowMode)
        {
            InitializeComponent();
            selectedWindowMode = windowMode;
            bmpClean           = new Bitmap(myImage);
            bmpBackground      = new Bitmap(bmpClean);
            bmpRegion          = new Bitmap(bmpClean);
            Bounds             = CaptureHelpers.GetScreenBounds();
            this.CursorPos     = this.PointToClient(Cursor.Position);
            rectIntersect.Size = new Size(Bounds.Width - 1, Bounds.Height - 1);
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            CalculateBoundaryFromMousePosition();
            timer.Tick       += new EventHandler(TimerTick);
            windowCheck.Tick += new EventHandler(WindowCheckTick);

            if (selectedWindowMode)
            {
                captureObjects = Engine.ConfigUI.SelectedWindowCaptureObjects;
                myRectangle    = new DynamicRectangle(CaptureType.SELECTED_WINDOW);
                WindowsListAdvanced wla = new WindowsListAdvanced();
                wla.IgnoreWindows.Add(Handle);
                wla.IncludeChildWindows = captureObjects;
                windows = wla.GetWindowsRectangleList();
            }
            else
            {
                myRectangle = new DynamicRectangle(CaptureType.CROP);

                if (Engine.ConfigUI.UseHardwareCursor)
                {
                    Cursor = Cursors.Cross;
                }
                else
                {
                    Cursor.Hide();
                }
            }

            using (Graphics gBackground = Graphics.FromImage(bmpBackground))
                using (Graphics gRegion = Graphics.FromImage(bmpRegion))
                {
                    gBackground.SmoothingMode = SmoothingMode.HighQuality;
                    gRegion.SmoothingMode     = SmoothingMode.HighQuality;

                    if ((selectedWindowMode && Engine.ConfigUI.SelectedWindowRegionStyles == RegionStyles.REGION_TRANSPARENT) ||
                        (!selectedWindowMode && Engine.ConfigUI.CropRegionStyles == RegionStyles.REGION_TRANSPARENT))
                    { // If Region Transparent
                        gRegion.FillRectangle(new SolidBrush(Color.FromArgb(Engine.ConfigUI.RegionTransparentValue, Color.White)),
                                              new Rectangle(0, 0, bmpRegion.Width, bmpRegion.Height));
                    }
                    else if ((selectedWindowMode && Engine.ConfigUI.SelectedWindowRegionStyles == RegionStyles.REGION_BRIGHTNESS) ||
                             (!selectedWindowMode && Engine.ConfigUI.CropRegionStyles == RegionStyles.REGION_BRIGHTNESS))
                    { // If Region Brightness
                        ImageAttributes imgattr = new ImageAttributes();
                        imgattr.SetColorMatrix(ColorMatrices.BrightnessFilter(Engine.ConfigUI.RegionBrightnessValue));
                        gRegion.DrawImage(bmpClean, new Rectangle(0, 0, bmpRegion.Width, bmpRegion.Height), 0, 0,
                                          bmpRegion.Width, bmpRegion.Height, GraphicsUnit.Pixel, imgattr);
                    }
                    else if ((selectedWindowMode && Engine.ConfigUI.SelectedWindowRegionStyles == RegionStyles.BACKGROUND_REGION_TRANSPARENT) ||
                             (!selectedWindowMode && Engine.ConfigUI.CropRegionStyles == RegionStyles.BACKGROUND_REGION_TRANSPARENT))
                    { // If Background Region Transparent
                        gBackground.FillRectangle(new SolidBrush(Color.FromArgb(Engine.ConfigUI.BackgroundRegionTransparentValue, Color.White)),
                                                  new Rectangle(0, 0, bmpBackground.Width, bmpBackground.Height));
                    }
                    else if ((selectedWindowMode && Engine.ConfigUI.SelectedWindowRegionStyles == RegionStyles.BACKGROUND_REGION_BRIGHTNESS) ||
                             (!selectedWindowMode && Engine.ConfigUI.CropRegionStyles == RegionStyles.BACKGROUND_REGION_BRIGHTNESS))
                    { // If Background Region Brightness
                        ImageAttributes imgattr = new ImageAttributes();
                        imgattr.SetColorMatrix(ColorMatrices.BrightnessFilter(Engine.ConfigUI.BackgroundRegionBrightnessValue));
                        gBackground.DrawImage(bmpClean, new Rectangle(0, 0, bmpBackground.Width, bmpBackground.Height), 0, 0,
                                              bmpBackground.Width, bmpBackground.Height, GraphicsUnit.Pixel, imgattr);
                    }
                    else if ((selectedWindowMode && Engine.ConfigUI.SelectedWindowRegionStyles == RegionStyles.BACKGROUND_REGION_GRAYSCALE) ||
                             (!selectedWindowMode && Engine.ConfigUI.CropRegionStyles == RegionStyles.BACKGROUND_REGION_GRAYSCALE))
                    { // If Background Region Grayscale
                        ImageAttributes imgattr = new ImageAttributes();
                        imgattr.SetColorMatrix(ColorMatrices.GrayscaleFilter());
                        gBackground.DrawImage(bmpClean, new Rectangle(0, 0, bmpBackground.Width, bmpBackground.Height), 0, 0,
                                              bmpBackground.Width, bmpBackground.Height, GraphicsUnit.Pixel, imgattr);
                    }
                }

            brushClean      = new TextureBrush(bmpClean);
            brushBackground = new TextureBrush(bmpBackground);
            brushRegion     = new TextureBrush(bmpRegion);
        }