コード例 #1
0
ファイル: FormWebCamOD.cs プロジェクト: steev90/opendental
        private void timerScreenShots_Tick(object sender, EventArgs e)
        {
            //ticks every 5 minutes
            int extension = Phones.IsOnClock(IpAddressCur, Environment.MachineName);

            if (extension == 0)        //if this person is on break
            {
                return;                //don't save a screenshot
            }
            string folder = @"\\serverfiles\storage\My\Jordan\ScreenshotsByWorkstation\" + Environment.MachineName;

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            if (datePurged.Date != DateTime.Today)
            {
                string[] files = Directory.GetFiles(folder);
                for (int f = 0; f < files.Length; f++)
                {
                    if (files[f].EndsWith("db"))
                    {
                        continue;                        //skip thumbs.db
                    }
                    DateTime dtCreated = File.GetCreationTime(files[f]);
                    if (dtCreated.AddDays(7).Date < DateTime.Today)
                    {
                        File.Delete(files[f]);
                    }
                }
                datePurged = DateTime.Today;
            }
            //create the image-----------------------------------------------------------------
            Point origin = new Point(0, 0);
            int   right  = 0;
            int   bottom = 0;

            //all screens together form a giant image.  We just need to know where origin is as well as size.
            for (int s = 0; s < System.Windows.Forms.Screen.AllScreens.Length; s++)
            {
                if (System.Windows.Forms.Screen.AllScreens[s].WorkingArea.X < origin.X ||
                    System.Windows.Forms.Screen.AllScreens[s].WorkingArea.Y < origin.Y)
                {
                    //screen must be to top or left of primary.  Use its origin.
                    origin = new Point(System.Windows.Forms.Screen.AllScreens[s].WorkingArea.X, System.Windows.Forms.Screen.AllScreens[s].WorkingArea.Y);
                }
                if (System.Windows.Forms.Screen.AllScreens[s].WorkingArea.X + System.Windows.Forms.Screen.AllScreens[s].WorkingArea.Width > right)
                {
                    //screen must be to right of primary.  Use its right-most extension.
                    right = System.Windows.Forms.Screen.AllScreens[s].WorkingArea.X + System.Windows.Forms.Screen.AllScreens[s].WorkingArea.Width;
                }
                if (System.Windows.Forms.Screen.AllScreens[s].WorkingArea.Y + System.Windows.Forms.Screen.AllScreens[s].WorkingArea.Height > bottom)
                {
                    //screen must be to bottom of primary.  Use its bottom-most extension.
                    bottom = System.Windows.Forms.Screen.AllScreens[s].WorkingArea.Y + System.Windows.Forms.Screen.AllScreens[s].WorkingArea.Height;
                }
            }
            //calculate total width and height, remembering that origin can be negative
            Size   sizeAllScreens = new Size(right - origin.X, bottom - origin.Y);   //example 100-(-20)=120, or 100-20=80.
            Bitmap bmp            = new Bitmap(sizeAllScreens.Width, sizeAllScreens.Height);

            using (Graphics g = Graphics.FromImage(bmp)) {
                g.CopyFromScreen(origin, new Point(0, 0), sizeAllScreens);
            }
            //save the image----------------------------------------------------------------------
            //I tried a variety of file types.  The resulting file sizes were very similar.
            string filename = folder + "\\" + DateTime.Now.ToString("yyyy-MM-dd-HHmmssff") + ".jpg";

            bmp.Save(filename);
            //make a thumbnail with height of 50
            int      thumbW   = (int)((double)bmp.Width / (double)bmp.Height * 50d);
            Bitmap   bmpThumb = new Bitmap(thumbW, 50);
            Graphics gThumb   = Graphics.FromImage(bmpThumb);

            gThumb.DrawImage(bmp, 0, 0, thumbW, 50);
            gThumb.Dispose();
            gThumb = null;
            Phones.SetScreenshot(extension, filename, bmpThumb);          //IpAddress192,bitmapSmall,Environment.MachineName);
        }