Python Forum
display error, png with transparent background
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
display error, png with transparent background
#3
This works as expected on my system. Will you please post enough code to produce the problem?
import pygame
pygame.init ()
SCREEN = pygame.display.set_mode ((300, 100))
TRANSPARENT = (0, 0, 0)

def create_image(file, color=None):
	"""
	Create image from a file.  If color is specified, replace all FOREGROUND
	pixels with color pixels.  Modify image so TRANSPARENT colored pixels are
	transparent.
	"""
	if color:
		# Recolor the image
		image = Image.open(file).convert("RGB")
		for xy in product(range(image.width), range(image.height)):
			if image.getpixel(xy) == FOREGROUND:
				image.putpixel(xy, color)
		image = pygame.image.fromstring(image.tobytes(), image.size, "RGB")
	else:
		image = pygame.image.load(file)
	image.set_colorkey(TRANSPARENT)
	return image.convert_alpha()

paddle = create_image ('paddle.png')
while True :
	for event in pygame.event.get () :
		if event.type == pygame.QUIT :
			pygame.quit ()
			quit ()

	SCREEN.fill ((0, 0, 0))
	SCREEN.blit (paddle, (70, 40))
	pygame.display.update ()
metulburr and menator01 like this post

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
RE: display error, png with transparent background - by BashBedlam - Mar-13-2022, 01:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [pygame] transparent rects SheeppOSU 2 3,326 Jun-10-2019, 03:41 PM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020