Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageGrab cannot get correct resolution screenshot for Windows 10 zoom #3626

Closed
HanqingTony opened this issue Feb 2, 2019 · 1 comment
Closed

Comments

@HanqingTony
Copy link

HanqingTony commented Feb 2, 2019

What did you do?

I have a large screen and i customed my win10 screen zooming on 125% , then i find that the function "ImageGrab" cannot work correctly,

What did you expect to happen?

I want get a screenshot of fullscreen, but it gave me part of it

What actually happened?

First I used default parameters,the function should have been given me a 1080p picture as my screen resolution, but only a 864p one, just topleft part of my screen. then i used some parameters in order to force set the function to give me screenshot on 1080p but the result is a picture seem like previous 864p picture with terrible black bar on right and below
it is obvious that 864p*125% =1080p, i think the reason caused this problem may concerned about the customed zooming of windows.

What are your OS, Python and Pillow versions?

  • OS: win10 x64 with 125% zooming
  • Python: 3.70
  • Pillow: 5.00

Origin code:

def scanScreen(tpl):
    capture=ImageGrab.grab()
    capture.save('capture.png') 
    pic=cv2.imread('capture.png')
    return findPosition(pic,tpl)

Code can work correctly

I find another way to get my screenshot by use WinAPI,it is fast and always work correctly, code is here, hope helpful

import win32gui, win32ui, win32con, win32api
def window_capture(filename):
  hwnd = 0 # window ID , '0' means the activated window 
  #get Divice Context
  hwndDC = win32gui.GetWindowDC(hwnd)
  #get mfcDC
  mfcDC = win32ui.CreateDCFromHandle(hwndDC)
  saveDC = mfcDC.CreateCompatibleDC()
  # create bigmap for picture saving
  saveBitMap = win32ui.CreateBitmap()
  # get Moniter info
  MoniterDev = win32api.EnumDisplayMonitors(None, None)
  w = MoniterDev[0][2][2]
  h = MoniterDev[0][2][3]
  # print w,h   #picture size
  # create bitmap space
  saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)
  # save the screenshot to saveBitmap
  saveDC.SelectObject(saveBitMap)
  # from topleft(0,0)to bottomright(w,h)
  saveDC.BitBlt((0, 0), (w, h), mfcDC, (0, 0), win32con.SRCCOPY)
  saveBitMap.SaveBitmapFile(saveDC, filename)
@radarhere radarhere changed the title “ImageGrab” cannot get correct resolution screenshot while win10 customed zooming ImageGrab cannot get correct resolution screenshot while win10 customed zooming May 2, 2019
@radarhere radarhere changed the title ImageGrab cannot get correct resolution screenshot while win10 customed zooming ImageGrab cannot get correct resolution screenshot for Windows 10 zoom May 4, 2019
@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to In progress in Pillow May 11, 2019
@radarhere
Copy link
Member

#4000 has now been merged, making the Windows screenshot functionality dpi aware.

Pillow automation moved this from In progress to Closed Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Pillow
  
Closed
Development

No branches or pull requests

3 participants