2
我是Python和pyGame的新手,我在縮放圖像時遇到了問題。 我想放大pygame中的圖像。 Pygame的文件稱,pyGame圖像縮放並不像預期的那樣工作
pygame.transform.scale()
應該擴展到新的分辨率。 但在我的下面的例子中它不起作用 - 它裁剪圖像,而不是調整它的大小!? 我在做什麼錯?
#!/usr/bin/env python3
# coding: utf-8
import pygame
from pygame.locals import *
# Define some colors
BLACK = (0, 0, 0)
pygame.init()
# Set the width and height of the screen [width, height]
screen = pygame.display.set_mode((1920, 1080))
pic = pygame.image.load('test.jpg').convert()
pic_position_and_size = pic.get_rect()
# Loop until the user clicks the close button.
done = False
# Clear event queue
pygame.event.clear()
# -------- Main Program Loop -----------
while not done:
for event in pygame.event.get():
if event.type == QUIT:
done = True
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
done = True
# background in black
screen.fill(BLACK)
# Copy image to screen:
screen.blit(pic, pic_position_and_size)
# Update the screen with what we've drawn.
pygame.display.flip()
pygame.display.update()
pygame.time.delay(10) # stop the program for 1/100 second
# decreases size by 1 pixel in x and y axis
pic_position_and_size = pic_position_and_size.inflate(-1, -1)
# scales the image
pic = pygame.transform.scale(pic, pic_position_and_size.size)
# Close the window and quit.
pygame.quit()
非常感謝您的快速答覆!解決了我的問題!但是,我想知道爲什麼這在pygame文檔中沒有提及...花了我幾個小時來玩,我嘗試了一切...... – Franky1