View Single Post
Old 03-03-2016, 08:34 AM
bonedoc bonedoc is offline
Junior Contributor
Join Date: Mar 2006
Posts: 376
Default Why grabbing screen graphics has different results on diferent computers?

I have a situation where I am grabbing a portion of the screen and printing it. It has worked great on the computer I am debugging with. However, I have tried it on another computer and the image is offset. It is getting a little bit to the top and left of the image. The 2 computers have different screen sizes, but I thought my code handled this. Does anyone know what this could be? picDisplayWindow is a picture box I am getting the image from. I know there are other ways to get this image, but I am doing the screen graphics because I have some transparency things I am using and need the screen image.

Private Function BackgroundBitmap() As Bitmap
        Dim ScreenGrab As New Bitmap(picDisplayWindow.Width, picDisplayWindow.Height)
        Dim RealPosition As Point = picDisplayWindow.PointToScreen(Point.Empty)

        Dim gdest As Graphics = Graphics.FromImage(screenGrab)
        Dim gsrc As Graphics = Graphics.FromHwnd(IntPtr.Zero)
        Dim hSrcDC As IntPtr = gsrc.GetHdc()
        Dim hDC As IntPtr = gdest.GetHdc()
        Dim retval As Integer = BitBlt(hDC, 0, 0, ScreenGrab.Width, ScreenGrab.Height, hSrcDC, RealPosition.X, RealPosition.Y, CInt(CopyPixelOperation.SourceCopy))


        Return screenGrab


    End Function
Reply With Quote