locked
Take a screenshot of a certain area

    Question

  • I am working on a program, and i have it taking a screenshot. Im trying to get it ONLY to take it of a certain area of the screen. I dont know how to do that. Here is the code right now.

      Dim bounds As Rectangle
            Dim screenshot As System.Drawing.Bitmap
            Dim graph As Graphics
    
    
            bounds = Screen.PrimaryScreen.Bounds
    
    
            screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            graph = Graphics.FromImage(screenshot)
            graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
            PictureBox1.Image = screenshot
    
    
            Dim SaveFileDialog1 As New SaveFileDialog()
            SaveFileDialog1.Filter = "PNG|*.png|GIF|*.gif"
            If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
    
    
                If Not PictureBox1.Image Is Nothing Then
                    PictureBox1.Image.Save(SaveFileDialog1.FileName)
                End If
            End If
    Monday, November 09, 2009 8:20 PM

Answers

  • Change the bounds.X and bounds.Y to the Left, Top location of the area of the screen you want.
    • Marked as answer by sak904 Monday, November 09, 2009 9:56 PM
    Monday, November 09, 2009 9:48 PM

All replies

  • Change the bounds.X and bounds.Y to the Left, Top location of the area of the screen you want.
    • Marked as answer by sak904 Monday, November 09, 2009 9:56 PM
    Monday, November 09, 2009 9:48 PM
  • Thank you so much.
    Monday, November 09, 2009 9:56 PM