[SOLVED] OnscreenImage & PNMImage

Hi guys,

I’m trying to display a picture stored into a PNIMage object, using the OnscreenImage class, however I can’t find how. What I’d like to do is something like :

myPNMImageObject = PNMImage()
OnscreenImage(image = myPNMImageObject) # doesn't work

The official Panda3D’s reference doesn’t include any entry about OnscreenImage : panda3d.org/reference/1.7.2/ … hp#index_o
Actually, the only source of information I found is the manual, which is incomplete in my case : panda3d.org/manual/index.php/OnscreenImage

After doing some research, I found that some people use the PNMImage.write method to copy the content of the picture into a stringstream object :

myPNMImageObject.write(myStringStreamObject, 'screenshot.png')

Then what I tried to do, is create a file object in python and copy back the data :

f = open('screenshot.png', 'wb').write(myStringStreamObject.getData())
OnscreenImage(image = f)

However my technique doesn’t seem to be working.

If you can help, me thanks a lot! :smiley:

No worries, this took me quite some time to figure out as well,
But only because it was explained to me more difficultly.

from direct.gui.OnscreenImage import OnscreenImage
MyPNMimageObject = OnScreenImage(image = 'filepatch/image.extension', pos = (x, 0, z))

Hi Luna,

First of all, even if you didn’t get my question, thank you for your answer. In fact, my problem is that I don’t want to load a picture from a plain picture file but from a PNMImage. So I can’t do :

image = 'filepatch/image.extension'

To be more explicit, I have a client powered by Panda3D that receives a serialized (with cPickle) PNMImage object from a server. The client must then display this PNMImage to screen. To do this, the only solution I found is to load the PNMImage object into the OnscreenImage

I’ll try some other tricks to find a solution and keep you up to date.

Again, thank you :wink:

I did something like this once, here is what worked for me:

myPNMImageObject = PNMImage() 
myTextureObject = Texture()
OnscreenImage(image = myTextureObject)

Thank you so much ! :smiley: