小编Joh*_*ohn的帖子

PyGame将cStringIO加载为图像

所以,我在网上尝试了一些解决方案,但每个都返回一个不同的错误.最近我决定尝试这样的事情:

import cStringIO, pygame, os
from pygame.locals import *

pygame.init()
mainClock = pygame.time.Clock()
WINDOWWIDTH = 640
WINDOWHEIGHT = 480
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
pygame.display.set_caption('StringIO Test')

with open("image.png", "rb") as infile:
    outfile = cStringIO.StringIO()
    outfile.write(infile.read())


class DummyFile:
    def __init__(self, data):
       self.data = data
        self.pos = 0

    def read(self, size=None):
        start = self.pos
        end = len(self.data) - 1

        if size is not None:
            end = min(len(self.data), self.pos + size)

        self.pos = end
        return self.data[start:end]

    def seek(self, offset, whence=0):
        if whence …
Run Code Online (Sandbox Code Playgroud)

python pygame image stringio

2
推荐指数
1
解决办法
587
查看次数

标签 统计

image ×1

pygame ×1

python ×1

stringio ×1