有没有办法调整rawimage的宽度和高度?

时间:2017-01-15 04:32:55

标签: python pygame pyglet

我想调整rawimage的宽度和高度

通过做一些研究,我发现我可以简单地做到

rawimage.width = (value whatever width I desire)
rawimage.height = (value whatever height I desire)

然后又出现了另一个问题。它给了我以下错误:

  

video = pygame.image.frombuffer(pixels,(rawimage.width,rawimage.height),'RGBA')   ValueError:缓冲区长度不等于格式和分辨率大小

我无法找到解决该问题的方法。无论如何都要解决这个问题吗?

代码:

import pygame
import pyglet

window = pyglet.window.Window(visible=False)
player = pyglet.media.Player()
player.queue(pyglet.media.load(".\\music_folder\\music_vid/servant_of_evil.mp4"))
player.play()
@window.event
def on_draw():
    #We have to convert the Pyglet media player's image to a Pygame surface
    global player



    rawimage = player.get_texture().get_image_data()

    print "rawimage "+str(rawimage)
    pixels = rawimage.get_data('RGBA', rawimage.width *4)


    video = pygame.image.frombuffer(pixels, (rawimage.width,rawimage.height), 'RGBA')

    #Blit the image to the screen
    gameDisplay.blit(video, (0, 0))
    pygame.display.update()
while True:
    pyglet.clock.tick()

    for window in pyglet.app.windows:
        window.switch_to()
        window.dispatch_events()
        window.dispatch_event('on_draw')

0 个答案:

没有答案