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.
Wtf…
Anyway:
hmap is a heightmap in PNMImage format, and here’s my code:
hmap.write(hmap,"./world")
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')
ss.getData()
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.