private static void TakeScreenCapture(string rxNumber, bool isPartial) { string _path = @"c:\temp\C&RProductionIssues\" + DateTime.Now.ToString("MMddyy") + "/"; string _partial = "_partial"; string _full = "_full"; string _filePath = string.Empty; if (!Directory.Exists(_path)) { Directory.CreateDirectory(_path); } using (ScreenCapture sc = new ScreenCapture()) { Image img = ScreenCapture.CaptureActiveWindow(); if (isPartial) { _filePath = @_path + "/" + rxNumber + _partial + ".jpg"; } else { _filePath = @_path + "/" + rxNumber + _full + ".jpg"; } img.Save(_filePath, ImageFormat.Jpeg); } }
private void CaptureActiveWindow() { Bitmap bmp = ScreenCapture.CaptureActiveWindow(); if (bmp != null) { var captureFileName = GetCaptureFileName(false); _logger.Debug($"Saving active window into: {captureFileName}"); UpdateFileStatus(captureFileName); bmp.Save(captureFileName, ImageFormat.Png); } }
void SaveAsImage() { menu.Visible = false; btnRefresh.Visible = false; btnChangeSeat.Visible = false; btnInfo.Visible = false; btnClose.Visible = false; this.Size = new Size(panel1.Size.Width + 70, panel1.Size.Height + 70); panel1.Location = new Point(35, 35); saveFileDialog1.ShowDialog(); Thread.Sleep(500); this.Focus(); var image = ScreenCapture.CaptureActiveWindow(); if (saveFileDialog1.FileName != string.Empty) { switch (saveFileDialog1.FilterIndex) { case 1: image.Save(saveFileDialog1.FileName, ImageFormat.Jpeg); MessageBox.Show("JPG 파일로 저장하였습니다.", "S8SeatChange"); break; case 2: image.Save(saveFileDialog1.FileName, ImageFormat.Png); MessageBox.Show("PNG 파일로 저장되었습니다.", "S8SeatChange"); break; } } else { MessageBox.Show("다시 한 번 지정해주세요."); } this.Size = new Size(623, 407); panel1.Location = new Point(35, 62); menu.Visible = true; btnRefresh.Visible = true; btnChangeSeat.Visible = true; btnInfo.Visible = true; btnClose.Visible = true; }
//private Bitmap MyImage; private void printScreenButton_Click(object sender, EventArgs e) { //method 1 //generate a screenshot //Bitmap pic= GenerateScreenshot("http://google.ro"); //show it in a picturebox //pictureBox2.Image = pic; //pictureBox2.Visible = true; //method 2 //ScreenCapture sc = new ScreenCapture(); //// capture entire screen, and save it to a file //Image img = sc.CaptureScreen(); //// display image in a Picture control named imageDisplay //pictureBox2.Image = img; //pictureBox2.Visible = true; //// capture this window, and save it //sc.CaptureWindowToFile(Handle, "C://temp2.gif", ImageFormat.Gif); //method 3 var image = ScreenCapture.CaptureActiveWindow(); pictureBox2.SizeMode = PictureBoxSizeMode.CenterImage; pictureBox2.BorderStyle = BorderStyle.Fixed3D; pictureBox2.Image = image; pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox2.Visible = true; //try //{ // image.Save(@"C:\\temp\\snippetsource.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); //} //catch(Exception ex) //{ // //MessageBox.Show(ex.ToString()); //} //method 4 //Rectangle bounds = this.Bounds; //using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height)) //{ // using (Graphics g = Graphics.FromImage(bitmap)) // { // g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size); // } // bitmap.Save("C://test.jpg", ImageFormat.Jpeg); //} //method 5 /* * // Sets up an image object to be displayed. * if (MyImage != null) * { * MyImage.Dispose(); * } * * // Stretches the image to fit the pictureBox. * pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage; * MyImage = pic; * pictureBox2.Visible = true; * pictureBox2.BackgroundImage = MyImage; */ }