PNMImage.write Arguments Make No Sense! (Solved)

Where do I get an Ostream object? This obviously means an output stream, but I don’t know how to just pull one out of my…

Anyway, I’ve been fiddling with this for some time, the possible arguments being different gets confusing, but I can’t get it to recognize making a PNG filetype whether I put that in the name or try to put some sort of wierd PNMFileType thing into the third argument.



hmap is a heightmap in PNMImage format, and here’s my code:


I realize that hmap isn’t the right argument to put there, but what the heck is? How can I get it to write my heightmap image to a file called “world.png” in png format?


In general, most Panda functions that accept a filename want you to wrap it in a Filename class, as shown, rather than pass it in as a simple string.

There is another flavor of write() that accepts an Ostream. This is mainly for advanced uses, like for writing to an in-memory buffer. The StringStream class is the easiest way to get a writable Ostream:

ss = StringStream()
p.write(ss, 'png')


Also, don’t be fooled by the error message, which tells you that the first parameter should be a PNMimage. That first parameter is self, which Python supplies by default. The parameters you supply begin with the second parameter listed.


I even had write(Filetype("./world")), which ofc did nothing but write an empty file, at one point. So close yet so far! lol

Thank you, once again, sir. I’ll be sure to note you somewhere in my code as a big help when it gets done. :slight_smile:

EyesOfARaven, drwr is panda3d itself in human form.