2

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.

Here is the image:

Here is the image

and here is how it looks in pygame

enter image description here

with the code of:

import pygame

screen = pygame.display.set_mode((500,500))
img = pygame.image.load("C:/Users/socia/Downloads/9nA8s.png")
img = pygame.transform.scale(img, (500,500))

isrunning = True
while isrunning:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            isrunning = False

    screen.blit(img, (0,0))
    pygame.display.update()

How could I draw similar images like the first one mentioned and how could I properly implement it in pygame.

Anything would be greatly appreciated, thanks!

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Yawn
  • 71
  • 7
  • That's not a vector image, it's a png. – Peter Wood Dec 29 '20 at 14:04
  • Perhaps this question is relevant: https://stackoverflow.com/questions/4001340/can-pygame-use-vector-art, also the [CairoPyGame](http://www.pygame.org/wiki/CairoPygame) tutorial linked in the answer. – Peter Wood Dec 29 '20 at 14:06
  • .. see also [SVG rendering in a PyGame application](https://stackoverflow.com/questions/120584/svg-rendering-in-a-pygame-application) – Rabbid76 Dec 29 '20 at 18:28

1 Answers1

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()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174