Example #1
0
        /// <summary>
        /// Converts a canvas to a bitmap object. This object can be saved and
        /// viewed by Bitmap.Save() and is also used for direct displaying and
        /// for pixel-by-pixel image comparison.
        /// </summary>
        /// <param name="canvas">Canvas with elements to paint.</param>
        /// <returns>The painted bitmap</returns>
        public static Bitmap Paint(ICanvas canvas)
        {
            var image = new Bitmap(
                canvas.Environment.CanvasWidth,
                canvas.Environment.CanvasHeight);

            using (var gfx = Graphics.FromImage(image))
            {
                gfx.CompositingMode    = CompositingMode.SourceOver;
                gfx.SmoothingMode      = SmoothingMode.AntiAlias;
                gfx.CompositingQuality = CompositingQuality.HighQuality;
                foreach (var element in canvas.Elements)
                {
                    Paint(element, gfx);
                }
            }
            // Turn blurring on or off
            bool blurring = false;

            Bitmap newImage = image;

            if (blurring)
            {
                // Create a filter
                AForge.Imaging.Filters.Blur filter = new AForge.Imaging.Filters.Blur();
                // Apply the filter
                newImage = filter.Apply(image);
            }
            return(newImage);
        }
Example #2
0
        private static Image DrawRoundedRectangle(
            Graphics g,
            Brush b,
            Rectangle rec,
            int radius,
            RoundedCorners corners,
            Image img)
        {
            int x        = rec.X;
            int y        = rec.Y;
            int diameter = radius * 2;
            var horiz    = new Rectangle(x, y + radius, rec.Width, rec.Height - diameter);
            var vert     = new Rectangle(x + radius, y, rec.Width - diameter, rec.Height);

            g.FillRectangle(b, horiz);
            g.FillRectangle(b, vert);

            if ((corners & RoundedCorners.TopLeft) == RoundedCorners.TopLeft)
            {
                g.FillEllipse(b, x, y, diameter, diameter);
            }
            else
            {
                g.FillRectangle(b, x, y, diameter, diameter);
            }

            if ((corners & RoundedCorners.TopRight) == RoundedCorners.TopRight)
            {
                g.FillEllipse(b, x + rec.Width - (diameter + 1), y, diameter, diameter);
            }
            else
            {
                g.FillRectangle(b, x + rec.Width - (diameter + 1), y, diameter, diameter);
            }

            if ((corners & RoundedCorners.BottomLeft) == RoundedCorners.BottomLeft)
            {
                g.FillEllipse(b, x, y + rec.Height - (diameter + 1), diameter, diameter);
            }
            else
            {
                g.FillRectangle(b, x, y + rec.Height - (diameter + 1), diameter, diameter);
            }

            if ((corners & RoundedCorners.BottomRight) == RoundedCorners.BottomRight)
            {
                g.FillEllipse(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter, diameter);
            }
            else
            {
                g.FillRectangle(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter,
                                diameter);
            }
            AForge.Imaging.Filters.Blur blur = new AForge.Imaging.Filters.Blur();
            return(blur.Apply((Bitmap)img));
        }
Example #3
0
        private void btn_uygula_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0) // Gri seçildi.
            {
                Bitmap image = new Bitmap(pictureBox1.Image);
                Bitmap gri   = griYap(image);

                pictureBox2.Image = gri;
            }
            if (comboBox1.SelectedIndex == 1) // Binary seçildi.
            {
                Bitmap image  = new Bitmap(pictureBox1.Image);
                Bitmap binary = binaryYap(image);
                pictureBox2.Image = binary;
            }
            if (comboBox1.SelectedIndex == 2) // Sobel Kenar seçildi.
            {
                Bitmap image = new Bitmap(pictureBox1.Image);
                Bitmap sobel = sobelEdgeDetection(image);

                pictureBox2.Image = sobel;
            }
            if (comboBox1.SelectedIndex == 3) // Sobel Kenar seçildi.
            {
                Bitmap image  = new Bitmap(pictureBox1.Image);
                Bitmap median = medianFilter(image);

                pictureBox2.Image = median;
            }
            if (comboBox1.SelectedIndex == 4) // Sepia Fitreleme seçildi.
            {
                // load an image
                System.Drawing.Bitmap image = new Bitmap(pictureBox1.Image);
                // create filter
                AForge.Imaging.Filters.Sepia filter = new AForge.Imaging.Filters.Sepia();
                // apply filter
                System.Drawing.Bitmap newImage = filter.Apply(image);


                pictureBox2.Image = newImage;
            }
            if (comboBox1.SelectedIndex == 5) // Blur Fitreleme seçildi.
            {
                // load an image
                System.Drawing.Bitmap image = new Bitmap(pictureBox1.Image);
                // create filter
                AForge.Imaging.Filters.Blur filter = new AForge.Imaging.Filters.Blur();
                // apply filter
                System.Drawing.Bitmap newImage = filter.Apply(image);


                pictureBox2.Image = newImage;
            }
            if (comboBox1.SelectedIndex == 6) // Keskinleştirme Fitreleme seçildi.
            {
                // load an image
                System.Drawing.Bitmap image = new Bitmap(pictureBox1.Image);
                // create filter
                AForge.Imaging.Filters.Sharpen filter = new AForge.Imaging.Filters.Sharpen();
                // apply filter
                System.Drawing.Bitmap newImage = filter.Apply(image);

                pictureBox2.Image = newImage;
            }
            if (comboBox1.SelectedIndex == 7) // Hue Modifier Fitreleme seçildi.
            {
                // load an image
                System.Drawing.Bitmap image = new Bitmap(pictureBox1.Image);
                // create filter
                AForge.Imaging.Filters.HueModifier filter = new AForge.Imaging.Filters.HueModifier();
                // apply filter
                System.Drawing.Bitmap newImage = filter.Apply(image);

                pictureBox2.Image = newImage;
            }
        }
        private static Image DrawRoundedRectangle(
            Graphics g,
            Brush b,
            Rectangle rec,
            int radius,
            RoundedCorners corners,
            Image img)
        {
            int x = rec.X;
            int y = rec.Y;
            int diameter = radius * 2;
            var horiz = new Rectangle(x, y + radius, rec.Width, rec.Height - diameter);
            var vert = new Rectangle(x + radius, y, rec.Width - diameter, rec.Height);

            g.FillRectangle(b, horiz);
            g.FillRectangle(b, vert);

            if ((corners & RoundedCorners.TopLeft) == RoundedCorners.TopLeft)
                g.FillEllipse(b, x, y, diameter, diameter);
            else
                g.FillRectangle(b, x, y, diameter, diameter);

            if ((corners & RoundedCorners.TopRight) == RoundedCorners.TopRight)
                g.FillEllipse(b, x + rec.Width - (diameter + 1), y, diameter, diameter);
            else
                g.FillRectangle(b, x + rec.Width - (diameter + 1), y, diameter, diameter);

            if ((corners & RoundedCorners.BottomLeft) == RoundedCorners.BottomLeft)
                g.FillEllipse(b, x, y + rec.Height - (diameter + 1), diameter, diameter);
            else
                g.FillRectangle(b, x, y + rec.Height - (diameter + 1), diameter, diameter);

            if ((corners & RoundedCorners.BottomRight) == RoundedCorners.BottomRight)
                g.FillEllipse(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter, diameter);
            else
                g.FillRectangle(b, x + rec.Width - (diameter + 1), y + rec.Height - (diameter + 1), diameter,
                                diameter);
            AForge.Imaging.Filters.Blur blur = new AForge.Imaging.Filters.Blur();
            return blur.Apply((Bitmap)img);
        }