Quick answer: Pygame image.save(surf, "out.png") producing a fully opaque PNG? The source surface lacks an alpha channel — convert with convert_alpha() before saving.
A screenshot of a sprite with transparency saves with a solid background. The screen surface is 24-bit; alpha is dropped on save.
Surface Must Have Alpha
shot = pygame.Surface(size, pygame.SRCALPHA)
shot.blit(sprite, (0, 0))
pygame.image.save(shot, "out.png")Render to a 32-bit alpha-capable surface, then save. PNG preserves the alpha.
convert_alpha for Existing
For an already-loaded surface: surf2 = surf.convert_alpha(). Returns a new surface with alpha; save that.
JPEG Doesn’t Support Alpha
Saving as .jpg flattens alpha to background color (usually black). For lossy transparent images, stick with PNG or WebP.
Save BMP for Diagnostics
BMP supports 32-bit too. Use for debugging alpha-channel issues — the format is simpler to inspect with a hex editor than PNG.
Verifying
Saved PNG opens with transparency in any image viewer. Alpha channel data round-trips through save and reload.
“PNG saves alpha only if the source has it. SRCALPHA or convert_alpha first.”
For screenshots-with-transparency, render to an offscreen alpha surface throughout — the main display can’t carry alpha to a window anyway.