简体   繁体   中英

How to make a high quality screenshot in Python

I have this Python function and it works well taking a regular screenshot.

I would like to be able to take the screenshot in high resolution. Could this code be modified to accomplish this, or would I need to integrate with another library?

def SaveScreen(self):
    print "save screen"

    # SCREENSHOT_CWDSAVE
    if SCREENSHOT_CWDSAVE:
        if not os.path.exists(os.getcwd()+os.sep+"screenshot"):
            os.mkdir(os.getcwd()+os.sep+"screenshot")

        (succeeded, name) = grp.SaveScreenShotToPath(os.getcwd()+os.sep+"screenshot"+os.sep)
    elif SCREENSHOT_DIR:
        (succeeded, name) = grp.SaveScreenShot(SCREENSHOT_DIR)
    else:
        (succeeded, name) = grp.SaveScreenShot()
    # END_OF_SCREENSHOT_CWDSAVE

    if succeeded:
        pass
        """
        chat.AppendChat(chat.CHAT_TYPE_INFO, name + localeInfo.SCREENSHOT_SAVE1)
        chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SCREENSHOT_SAVE2)
        """
    else:
        chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SCREENSHOT_SAVE_FAILURE)

2 solutions for you: either you try another module like MSS (easy, efficient and creates high quality PNG pictures), either you change the code of the function SaveJPEG :

// https://pastebin.com/xAv30gK1 at line 169
return jpeg_save(pbyBuffer, uWidth, uHeight, 85, pszFileName) != 0;

You see the 85 ? It is the picture quality. Just change to 100 ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM