public Bitmap GetNewFrame(Bitmap source)
        {
            var newFrame = oilPainting.Apply(source);

            source.Dispose();
            return(newFrame);
        }
示例#2
0
        public Bitmap ToOilPainting(Bitmap Im)
        {
            AForge.Imaging.Filters.OilPainting Img = new OilPainting();
            Bitmap bmImage = AForge.Imaging.Image.Clone(new Bitmap(Im), PixelFormat.Format24bppRgb);

            return(Img.Apply(bmImage));
        }
示例#3
0
        public static Bitmap FilterImage(Bitmap img, int filter)
        {
            Bitmap sourceImage = img;

            sourceImage = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            IFilter myFilter;
            Bitmap  filteredImage = sourceImage;

            if (filter == Filters.filters["Greyscale"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                filteredImage = sourceImage;
            }
            else if (filter == Filters.filters["Sepia"])
            {
                myFilter      = new Sepia();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Invert"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Invert();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["RotateChannel"])
            {
                myFilter      = new RotateChannels();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Threshold"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new Threshold();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["FloydFilter"])
            {
                FloydSteinbergColorDithering myReduction = new FloydSteinbergColorDithering();
                filteredImage = myReduction.Apply(sourceImage);
            }
            else if (filter == Filters.filters["OrderedDithering"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new OrderedDithering();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Sharpen"])
            {
                myFilter      = new Sharpen();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["DifferenceEdgeDetector"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new DifferenceEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["HomogenityEdgeDetector"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new HomogenityEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Sobel"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new SobelEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Jitter"])
            {
                myFilter      = new Jitter(); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["OilPainting"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new OilPainting(); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["TextureFiltering"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Texturer(new TextileTexture(), 1.0, 0.8); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Median"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Median();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Mean"])
            {
                myFilter      = new Mean();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Blur"])
            {
                myFilter      = new GaussianBlur();
                filteredImage = myFilter.Apply(sourceImage);
            }

            //Console.Write(filteredImage.PixelFormat.ToString());
            //Console.Write(sourceImage.PixelFormat.ToString());
            filteredImage = ImageUtil.convert(filteredImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            return(filteredImage);
        }
示例#4
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Bitmap sourceImage = null;

            DA.GetData(0, ref sourceImage);
            string filter = "";

            DA.GetData(1, ref filter);


            sourceImage = ImageUtilities.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            IFilter myFilter;
            Bitmap  filteredImage = sourceImage;

            //Grayscale.CommonAlgorithms.Y.Apply
            switch (filter)
            {
            case "Greyscale":
                Console.Write("Applying: " + filter);
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                filteredImage = sourceImage;
                break;

            case "Sepia":
                Console.Write("Applying: " + filter);
                myFilter      = new Sepia();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Invert":
                Console.Write("Applying: " + filter);
                sourceImage   = ImageUtilities.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Invert();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "RotateChannel":
                Console.Write("Applying: " + filter);
                myFilter      = new RotateChannels();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Threshold":     //Need Extended Version
                Console.Write("Applying: " + filter);
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new Threshold();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "FloydFilter":
                Console.Write("Applying: " + filter);
                //sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                //myFilter = new FloydSteinbergColorDithering();
                FloydSteinbergColorDithering myReduction = new FloydSteinbergColorDithering();
                filteredImage = myReduction.Apply(sourceImage);
                //filteredImage = myFilter.Apply(sourceImage);
                break;

            case "OrderedDithering":
                Console.Write("Applying: " + filter);
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new OrderedDithering();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Sharpen":
                Console.Write("Applying: " + filter);
                myFilter      = new Sharpen();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "DifferenceEdgeDetector":
                Console.Write("Applying: " + filter);
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new DifferenceEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "HomogenityEdgeDetector":
                Console.Write("Applying: " + filter);
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new HomogenityEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Sobel":
                Console.Write("Applying: " + filter);
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new SobelEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Jitter":
                Console.Write("Applying: " + filter);
                myFilter      = new Jitter(); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "OilPainting":
                Console.Write("Applying: " + filter);
                myFilter      = new OilPainting(); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "TextureFiltering":
                Console.Write("Applying: " + filter);
                sourceImage   = ImageUtilities.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Texturer(new TextileTexture(), 1.0, 0.8); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Median":
                Console.Write("Applying: " + filter);
                myFilter      = new Median();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Mean":
                Console.Write("Applying: " + filter);
                myFilter      = new Mean();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            case "Blur":     //Need Extended Version
                Console.Write("Applying: " + filter);
                myFilter      = new GaussianBlur();
                filteredImage = myFilter.Apply(sourceImage);
                break;

            default:
                Console.Write("No Filter");
                break;
            }

            Console.Write(filteredImage.PixelFormat.ToString());
            Console.Write(sourceImage.PixelFormat.ToString());
            filteredImage = ImageUtilities.convert(filteredImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);



            DA.SetData(0, filteredImage);
        }
示例#5
0
    protected void Button_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(Server.MapPath("~/images/") + FileUpload1.FileName);
            Label5.Text = "File name: " + FileUpload1.PostedFile.FileName;

            String path;
            String pathURL;
            using (System.Drawing.Image tempImage = System.Drawing.Image.FromFile("C:\\inetpub\\wwwroot\\images\\" + FileUpload1.FileName))
            {
                // Create string to draw.
                String drawString = TextBox4.Text;

                // Create font and brush.
                Font       drawFont  = new Font("Impact", 100);
                SolidBrush drawBrush = new SolidBrush(Color.Red);

                // Create point for upper-left corner of drawing.
                PointF drawPoint = new PointF(75.0F, 25.0F);

                // Draw string to screen.
                using (Graphics g = Graphics.FromImage(tempImage))
                {
                    g.DrawString(drawString, drawFont, drawBrush, drawPoint);
                }
                using (var m = new MemoryStream())
                {
                    String time_stamp = Stopwatch.GetTimestamp().ToString();
                    String uniqueName = TextBox5.Text;
                    path    = Server.MapPath("/images/") + uniqueName + time_stamp + FileUpload1.FileName;
                    pathURL = "/images/" + uniqueName + time_stamp + FileUpload1.FileName;


                    new Bitmap(tempImage, 300, 300).Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
                    Image1.ImageUrl = pathURL;

                    // create a filter
                    Grayscale   GrayFilter  = new Grayscale(0.2125, 0.7154, 0.0721);
                    Sepia       SepiaFilter = new Sepia();
                    OilPainting OilFilter   = new OilPainting(15);


                    // apply the filter
                    Bitmap test = new Bitmap(tempImage, 300, 300);
                    if (RadioButtonList1.SelectedIndex == 0)
                    {
                    }
                    else if (RadioButtonList1.SelectedIndex == 1)
                    {
                        Bitmap sepiaImage = SepiaFilter.Apply(test);
                        sepiaImage.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
                        Image1.ImageUrl = pathURL;
                    }
                    else if (RadioButtonList1.SelectedIndex == 2)
                    {
                        Bitmap grayImage = GrayFilter.Apply(test);
                        grayImage.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
                        Image1.ImageUrl = pathURL;
                    }
                    else if (RadioButtonList1.SelectedIndex == 3)
                    {
                        Bitmap oilImage = OilFilter.Apply(test);
                        oilImage.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
                        Image1.ImageUrl = pathURL;
                    }
                }
            }



            ////These is where I submit the information to the database.
            string qemail    = Request.QueryString["email"];
            string memepath  = pathURL;
            string memetext  = TextBox4.Text;
            string timestamp = Stopwatch.GetTimestamp().ToString();
            int    baseLikes = 0;
            int    uploaded  = 0;

            string connectionString = "uid=myusername;server=192.168.12.136;port=3306;database=it210b;password=123456;";

            MySqlConnection connection = new MySqlConnection(connectionString);
            connection.Open();

            ////This is the command for grabbing the userID

            MySqlCommand IDCommand = new MySqlCommand();
            IDCommand.CommandText = "Select userId From it210b.users WHERE email = @qemail";
            IDCommand.Parameters.AddWithValue("@qemail", qemail);
            IDCommand.Connection = connection;
            string userID = IDCommand.ExecuteScalar().ToString();

            ////This is where I insert image info into DB. You have to assign your command a connection to use.
            MySqlCommand command = new MySqlCommand();
            command.Connection  = connection;
            command.CommandText = "Insert INTO it210b.images (imagePath, altText, userId, numLikes, uploaded) VALUES (@imagePath, @altText, @userId, @numLikes, @uploaded )";
            command.Prepare();

            command.Parameters.AddWithValue("@imagePath", memepath);
            command.Parameters.AddWithValue("@altText", memetext);
            command.Parameters.AddWithValue("@userId", userID);
            command.Parameters.AddWithValue("@numLikes", baseLikes);
            command.Parameters.AddWithValue("@uploaded", uploaded);

            command.ExecuteNonQuery();

            HtmlMeta meta = new HtmlMeta();
            meta.HttpEquiv = "Refresh";
            meta.Content   = "2;url=http://192.168.12.136:1337/memes";
            this.Page.Controls.Add(meta);
        }
        else
        {
            Label5.Text = "No file found. Please select a file and try again.";
        }
    }