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); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)