PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, May 7, 2022

[FIXED] how can we get rid of the blur in pygame image?

 May 07, 2022     blit, image, pygame, python, sprite     No comments   

Issue


    
    import pygame as pygame , sys
    
    pygame.init()
    size = (700,500)
    window_game = pygame.display.set_mode(size)
    print(pygame.mouse.get_cursor())
    _run_ = True
    
    
    class mySprite(pygame.sprite.Sprite):
        def __init__ (self,width,height,cord_x,cord_y,color):
            super().__init__()
            self.image = pygame.Surface([width,height])
            self.image.fill(color)
            self.rect = self.image.get_rect()
            self.rect.center = [cord_x,cord_y]
#my background image
    bgimg = pygame.image.load("download.jpg")
    bgimg = pygame.transform.smoothscale(bgimg, size)
    
    placeSP = [mySprite(50,20,100,150,(10,205,120))]
    placeSP_group = pygame.sprite.Group()
    
    Clock = pygame.time.Clock()
    FPS = 240
    while _run_:
    
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.QUIT
                sys.exit()
            placeSP.append(mySprite(50,20,100,170,(10,25,0)))
        pygame.display.flip()
        window_game.blit(bgimg,(0,0))
        placeSP_group.draw(window_game)
        placeSP_group.add(placeSP[:])
        Clock.tick(FPS)

now the problem I have is that the download.jpg is 4k res and if I try to fit that image in my window the img is very blurry and i have also tried many more img but they were all blurry do I try to get a picture of the window size or do i have to do something else pls tell me....


Solution

You can't. You can choose between a blurred image with pygame.transform.smoothscale

bgimg = pygame.transform.smoothscale(bgimg, size)

or a jagged image with pygame.transform.scale

bgimg = pygame.transform.scale(bgimg, size)

If you don't want that, you'll need to use a higher resolution image.



Answered By - Rabbid76
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing