pygame.surface in kivy Image widget

654 views
Skip to first unread message

neutral

unread,
Jan 2, 2013, 2:06:10 PM1/2/13
to kivy-...@googlegroups.com
Hello! Are there any way to display pygame surface inside Image widget? I've tried to convert it to Texture using pygame.Image.tostring/Texture.blit_buffer, but resulting texture was black. Even when I've tried to use the sample code from docs, it still remained black. I'm using kivy 1.4.2-dev on Android 4.0.4.

neutral

unread,
Jan 3, 2013, 11:19:49 AM1/3/13
to kivy-...@googlegroups.com
OK, I've managed to load pygame screen into a Kivy texture. But how to blit that texture in the Image? Example from docs (texture.blit_buffer example) not working - it shows just black screen.

четверг, 3 января 2013 г., 0:06:10 UTC+5 пользователь neutral написал:

neutral

unread,
Jan 5, 2013, 4:21:31 AM1/5/13
to kivy-...@googlegroups.com
One-man-thread? No matter, I've solved it. If someone is interested:

imports:
from pygame.image import tostring
from kivy.core.image import ImageData
from kivy.graphics.texture import Texture


code, where surface - pygame surface, image - kivy Image widget:
buffer = tostring(surface, 'RGB', True)
imdata = ImageData(width, height, 'rgb', buffer)
tex = Texture.create_from_data(imdata)
image.texture = tex


четверг, 3 января 2013 г., 0:06:10 UTC+5 пользователь neutral написал:
Hello! Are there any way to display pygame surface inside Image widget? I've tried to convert it to Texture using pygame.Image.tostring/Texture.blit_buffer, but resulting texture was black. Even when I've tried to use the sample code from docs, it still remained black. I'm using kivy 1.4.2-dev on Android 4.0.4.

Luis Bill

unread,
Aug 13, 2013, 6:14:18 PM8/13/13
to kivy-...@googlegroups.com
Its very hard to see what you are trying to do with just that much code.

After you define the texture wit image.texture = tex, how exactly are you displaying into the kivy window? What's the code that you are writing to do it?


Thank you very much for making this post, though. Its helpful.

Alexander Babayants

unread,
Aug 14, 2013, 3:36:55 AM8/14/13
to kivy-...@googlegroups.com

Nothing more must be done. In my app I had the Kivy window with an Image widget inside. Kivy widgets are event-driven, so when you change the texture property of the image widget, the widget updates automatically.

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/3jYJtVk5vPQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages