利用pygame来显示文件里的二进制图片图片

时间:2021-01-22 21:44:21
import requests
import pygame
from sys import exit


url = 'https://www.apiopen.top/satinApi?type=1&page=1'

resp = requests.get(url)

all_dict = resp.json()
list1 = all_dict["data"]
num = 0
for i in list1:
    img = requests.get(i["profile_image"])
    with open('img' + str(num) + '.jpg','bw') as f:
        f.write(img.content)
    num += 1

num = 0
pygame.init()
screen = pygame.display.set_mode((300,300))
screen.fill((255,255,255))
pygame.display.flip()
image = pygame.image.load('img'+str(num) + '.jpg')
new_image = pygame.transform.scale(image,(300,300))
screen.blit(new_image,(0,0))
pygame.display.flip()
while True:
    for event in pygame.event.get():
        if event.type == pygame .QUIT:
            exit()
    screen.fill((255, 255, 255))
    pygame.time.delay(1000)
    image = pygame.image.load('img' + str(num) + '.jpg')
    new_image = pygame.transform.scale(image,(300, 300))
    screen.blit(new_image,(0,0))
    pygame.display.flip()
    num += 1