有没有办法将 pygame 表面转换为 png 图像?
rgb_content = pygame.surfarray.array2d(canvas)
cv2.imwrite(file, rgb_content, [cv2.IMWRITE_PNG_COMPRESSION, 0])
我已经试过了,但它不起作用,因为它会横向翻转图像。将其设为灰度并且实际上并不保存它。
最佳答案
使用 save
image
模块的功能:
pygame.image.save()
save an image to disk
save(Surface, filename) -> None
This will save your Surface as either a BMP, TGA, PNG, or JPEG image. If the filename extension is unrecognized it will default to TGA. Both TGA, and BMP file formats create uncompressed files.
所以只需像这样使用它:
pygame.image.save(your_surface, "your_filename.png")
关于python - 将 pygame 表面转换为图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62528716/