C# - 擷取視窗影像並另存新檔

  • 60273
  • 0
  • C#
  • 2008-03-22

C# - 擷取視窗影像並另存新檔

C# - 擷取視窗影像並另存新檔

  1. private void button1_Click( object sender, EventArgs e)
  2. {
  3. Bitmap screenshot = new Bitmap(Width, Height, PixelFormat.Format32bppArgb );
  4. Graphics graph = Graphics.FromImage (screenshot);
  5. graph.CopyFromScreen (Location.X, Location.Y, 0, 0, Size, CopyPixelOperation.SourceCopy );
  6. SaveFileDialog sfd = new SaveFileDialog( );
  7. sfd.Filter = "Image File (*.png) | *.png";
  8. if (sfd.ShowDialog ( ) == DialogResult.OK )
  9. {
  10. string filename = sfd.FileName;
  11. screenshot.Save (filename);
  12. }
  13. }