Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python create and show screenshot

import numpy as np
import pyautogui
import scipy.ndimage
import pygame


class Viewer:
    def __init__(self, display_size):
        pygame.init()
        self.display = pygame.display.set_mode(display_size)
        self.pic = np.zeros((*display_size, 3), dtype=np.uint8)

    def set_title(self, title):
        pygame.display.set_caption(title)

    def set_image(self, image):
        self.pic = image

    def start(self):
        running = True
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False

            surf = pygame.surfarray.make_surface(self.pic)
            self.display.blit(surf, (0, 0))

            pygame.display.update()

        pygame.quit()


viewer = Viewer((700, 700))

screen_size = pyautogui.size()

img = pyautogui.screenshot()
img = np.array(img)
img = np.rot90(img)
img = np.flipud(img)
background = np.zeros((700, 700, 3), dtype=np.uint8)
img = scipy.ndimage.zoom(img, (min(700 / img.shape[0], 700 / img.shape[1]),
                               min(700 / img.shape[0], 700 / img.shape[1]), 1))
# blend the image with the background
background[int(350 - img.shape[0] / 2):int(350 + img.shape[0] / 2),
           int(350 - img.shape[1] / 2):int(350 + img.shape[1] / 2), :] = img
viewer.set_image(background)
viewer.start()
Source by datatofish.com #
 
PREVIOUS NEXT
Tagged: #python #create #show #screenshot
ADD COMMENT
Topic
Name
7+3 =