Python Forum
[PyGame] BufferProxy.raw problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] BufferProxy.raw problem
#2
(May-31-2018, 12:32 PM)Twitchy Wrote:
I can see the "start" and "end" but not the "buf.raw".

Sorry, I don't know why your code doesn't work. But the following works for me so maybe you can figure it out by trying to run this:

>>> import pygame
>>> import pygame.gfxdraw
>>> import numpy as np
>>> background_colour = (1, 1, 1)
>>> width, height = (256, 256)
>>> screen = pygame.Surface((width, height))
>>> pygame.draw.rect(screen, (8, 16, 32), (0, 0, 100, 100), 0)
<rect(0, 0, 100, 100)>
>>> s = screen.get_buffer()
>>> x = np.fromstring(s.raw, dtype='b').reshape(height, width, 4)
>>> x[0, 0]
array([32, 16,  8,  0], dtype=int8)
The problem I have is that it has switched the R, G, B values around. (I expected to get [8, 16, 32, 0] back).

Any idea why or how to avoid that would be appreciated.

(Nov-11-2018, 10:26 PM)billtubbs Wrote: The problem I have is that it has switched the R, G, B values around. (I expected to get [8, 16, 32, 0] back).

See this stackoverflow post for how I solved my problem.
Reply


Messages In This Thread
BufferProxy.raw problem - by Twitchy - May-31-2018, 12:32 PM
RE: BufferProxy.raw problem - by billtubbs - Nov-11-2018, 10:26 PM

Forum Jump:

User Panel Messages

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