Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers?
Go Back  Xtreme Visual Basic Talk > > > Why grabbing screen graphics has different results on diferent computers?


Reply
 
Thread Tools Display Modes
  #1  
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.

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
Reply With Quote
  #2  
Old 03-03-2016, 03:38 PM
passel's Avatar
passelWhy grabbing screen graphics has different results on diferent computers? passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,015
Default

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.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 03-03-2016, 03:43 PM
Cerian Knight's Avatar
Cerian KnightWhy grabbing screen graphics has different results on diferent computers? Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,178
Default

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.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #4  
Old 03-04-2016, 07:55 AM
bonedoc bonedoc is offline
Junior Contributor
 
Join Date: Mar 2006
Posts: 376
Default

Quote:
Originally Posted by passel View Post
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.
Reply With Quote
  #5  
Old 03-04-2016, 01:57 PM
PlausiblyDamp's Avatar
PlausiblyDampWhy grabbing screen graphics has different results on diferent computers? PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,057
Default

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.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #6  
Old 03-04-2016, 08:14 PM
Cerian Knight's Avatar
Cerian KnightWhy grabbing screen graphics has different results on diferent computers? Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,178
Default

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
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
Reply

Tags
dim, graphics, screen, computer, function, image, intptr, screengrab, hsrcdc, computers, grabbing, realposition, gdest, bitmap, gsrc, picdisplaywindow.height, screengrab.dispose, return, backgroundbitmap, bitblthdc, screengrab.width, screengrab.height, realposition.y, realposition.x, integer


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers? Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers?
 
Why grabbing screen graphics has different results on diferent computers?
Why grabbing screen graphics has different results on diferent computers?
 
-->