Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Interface and Graphics (http://www.xtremevbtalk.com/-net-interface-and-graphics/)
-   -   Why grabbing screen graphics has different results on diferent computers? (http://www.xtremevbtalk.com/-net-interface-and-graphics/328071-grabbing-screen-graphics-results-diferent-computers.html)

bonedoc 03-03-2016 08:34 AM

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.

Code:

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))

        gdest.ReleaseHdc()
        gsrc.ReleaseHdc()

        Return screenGrab

        screenGrab.Dispose()

    End Function


passel 03-03-2016 03:38 PM

You posted in the Legacy VB4/5/6 forum (VB6 released in 1998), but the code looks like VB.Net.

I'll move this to a Vb.Net forum.
I wonder if there is some sort of DPI difference issue going on, i.e. one machine may have a high density display and is using an enlarged (125% for instance) display setting so that pixel references differ between what .Net PointToScreen converts to and what bitblt understands.

Cerian Knight 03-03-2016 03:43 PM

For the PictureBox (that is under my control), I seem to recall manually choosing Appearance: Flat and BorderStyle: None in order to make sure that I didn't have to adjust my code for possible OS/GUI variations that I theorized could be induced by the default (3D/Fixed Single) property settings.

Other than that, no ideas.

bonedoc 03-04-2016 07:55 AM

Quote:

Originally Posted by passel (Post 1409569)
You posted in the Legacy VB4/5/6 forum (VB6 released in 1998), but the code looks like VB.Net.

I'll move this to a Vb.Net forum.
I wonder if there is some sort of DPI difference issue going on, i.e. one machine may have a high density display and is using an enlarged (125% for instance) display setting so that pixel references differ between what .Net PointToScreen converts to and what bitblt understands.


I think you may be correct. The other computer is a tablet and the overall software resolution looks different. I may not be able to make it work in all situations unless the screen settings are changed.

PlausiblyDamp 03-04-2016 01:57 PM

Never tried this personally but it looks like https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx might be of some help as it looks like you can use it to set the DPI of your ScreenGrab bitmap.

You should be able to get the current DPI from the gsrc bitmap.

Cerian Knight 03-04-2016 08:14 PM

Funny, my old signature was regarding High DPI awareness, but for some reason I thought it didn't apply to a PictureBox, so didn't consider it a solution.

Here are a few more links to consider, including a description of the scaling behavior on a Surface Pro:
https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx
https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx
https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx


All times are GMT -6. The time now is 03:34 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.