VB.NET Screen Capture

2019-08-14 05:33发布

问题:

Hello all i am using the below code to capture the screenshot of the black panel of my window form in visual basic 2005.

My problem is that I want the red border image to come in between and to be full.

My code :

    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.Format32bppRgb)  
    graph = Graphics.FromImage(screenshot)  
    graph.CopyFromScreen(618, 191, 850, 455, bounds.Size, CopyPixelOperation.SourceCopy)  
    screenshot.Save("d:\\dcap.bmp", Imaging.ImageFormat.Bmp)  `

回答1:

Your code works well just set the bounds to zero

 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.Format32bppRgb)
    graph = Graphics.FromImage(screenshot)
    graph.CopyFromScreen(0, 0, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
    screenshot.Save("d:\\dcap.jpg", Imaging.ImageFormat.Bmp)