Click here to Skip to main content

somu arbune asked:

Open original thread
public partial class Form1 : Form
    {
        static Bitmap img;      
      
        private void timer1_Tick(object sender, EventArgs e)
        {
            Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) + @"C:\new\Pranay\ScreenCaptures");        
 
            if (!string.IsNullOrEmpty(axWindowsMediaPlayer1.URL))
            {               
                Image ret = null;
                try
                {
 
//--------------------------------------------------- take picture BEFORE saveFileDialog pops up!!-----------------------------------------------------
                    Bitmap bitmap = new Bitmap(axWindowsMediaPlayer1.Width, axWindowsMediaPlayer1.Height);
 
                    //EuclideanColorFiltering filter = new EuclideanColorFiltering();
                    //filter.CenterColor = Color.FromArgb(215, 30, 30);
                    //filter.Radius = 100;
                    //filter.ApplyInPlace(bitmap);

                    //    newPicBox.Image = bitmap;

                    {
                        Graphics g = Graphics.FromImage(bitmap);
                        {
                            Graphics gg = axWindowsMediaPlayer1.CreateGraphics();
                            {
                                FrameTimer.Start();
                                this.BringToFront();
                                g.CopyFromScreen(axWindowsMediaPlayer1.PointToScreen(new System.Drawing.Point()).X, axWindowsMediaPlayer1.PointToScreen(new System.Drawing.Point()).Y, 0, 0, new System.Drawing.Size(axWindowsMediaPlayer1.Width, axWindowsMediaPlayer1.Height - 60));
 
                                FramepictureBox.Image = bitmap;
 
                                //Change the color of the pixel=-------------------Image comparing--------------------------------------------------

                                Bitmap img1 = bitmap;
                                if (img != null)
                                {
 
                                    float avg = 0;
                                    float avg1 = 0;
 
                                    if (img1.Width == img.Width && img1.Height == img.Height)
                                    {
                                        for (int i = 170; i < 296; i++)
                                        {
                                            for (int j = 70; j < 100; j++)
                                            {
                                                // img1.SetPixel(i, j, Color.Red);
                                                Color img1_ref = img1.GetPixel(i, j);
                                                Color img2_ref = img.GetPixel(i, j);
                                                float oneR = img1_ref.R;
                                                float twoR = img2_ref.R;
                                                float diffR = Math.Abs(oneR - twoR);
 
                                                float oneG = img1_ref.G;
                                                float twoG = img2_ref.G;
                                                float diffG = Math.Abs(oneG - twoG);
                                                float oneB = img1_ref.B;
                                                float twoB = img2_ref.B;
                                                float diffB = Math.Abs(oneB - twoB);
                                                float perR = (diffR / 255) * 100;
                                                float perG = (diffG / 255) * 100;
                                                float perB = (diffB / 255) * 100;
                                                float netPer = (perB + perG + perR) / 3;
                                                avg += netPer;
                                            }
                                        }
                                        /*-------------------------------------------Second Rectangle----------------------------------------------*/
 
                                      same as above but change i Co-ordinates
 

                                        int totalPixels = 161 * 50;
 
                                        int totalPixels1 = 20 * 166;
 
                                        float netAvg = avg / totalPixels;
                                        float netAvg1 = avg1 / totalPixels1;
 
                                        RGBlbl.Text = netAvg1.ToString();
                                        RGBlbl1.Text = netAvg.ToString();
 
                                        if (netAvg > 0.5)
                                        {
                                            if (netAvg1 > 2)
                                            {
                                              
                                                Pen pen = new Pen(Color.Red, 1);
                                                g.DrawRectangle(pen, 50, 120, 161, 50);
                                                using (MemoryStream ms = new MemoryStream())                                                {
                                                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                                                    ret = System.Drawing.Image.FromStream(ms);
 
                                                    ret.Save(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) + @"C:\new\Pranay\ScreenCaptures\" + "IMG" + i + ".jpeg", ImageFormat.Jpeg);
 
                                                }
                                                i++;
                                                ImageConverter converter = new ImageConverter();
                                                byte[] imgbit = (byte[])converter.ConvertTo(img1, typeof(byte[]));
 

                                                string strcon = "Data Source=U8-PC\\SQLEXPRESS;Initial Catalog=TrafficAnalysis;Integrated Security=true";
                                                SqlConnection mycon = new SqlConnection(strcon);
                                                mycon.Open();
                                                string strquery = "insert into Image(ImageData) values('" + imgbit + "')";
                                                SqlCommand cmd = new SqlCommand(strquery, mycon);
                                                cmd.ExecuteNonQuery();
                                            }
                                        }
                                        else
                                        {
 
                                        }
                                    }
                                }
                            }
                        }
                        //  afterwards save bitmap file if user wants to
                        img = bitmap;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
        }
Tags: C#

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100