How Can You Draw More Detailed/smoother Images In Pygame?
I have been trying to get into the vector-styled art world and recently I've tried blitting a vector image using the .blit() method but when I do blit it, it comes out as pixelated
Solution 1:
Use pygame.transform.smoothscale
instead of pygame.transform.scale
:
img = pygame.transform.scale(img, (500,500))
img = pygame.transform.smoothscale(img, (500,500))
While pygame.transform.scale
performs a fast scaling with the nearest pixel, pygame.transform.smoothscale
scales a surface smoothly to any size with interpolation of the pixels.
For an even better result, you may want to switch to a vector graphic format such as SVG (Scalable Vector Graphics).
See the answers to the question SVG rendering in a PyGame application a nd the following minimal example:
import pygame
pygame.init()
window = pygame.display.set_mode((300, 300))
clock = pygame.time.Clock()
pygame_surface = pygame.image.load('Ice.svg')
run = True
while run:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
window.fill((127, 127, 127))
window.blit(pygame_surface, pygame_surface.get_rect(center = window.get_rect().center))
pygame.display.flip()
pygame.quit()
exit()
Post a Comment for "How Can You Draw More Detailed/smoother Images In Pygame?"