I’m having a bit of a problem with saving images that I’ve created with Image.New()
Here is some code…
import Blender
from Blender import *
newimg = Image.New('myimage',256,256,24)
#Put one pixel in image
newimg.setPixelF(128,128,(1.0,1.0,1.0,1.0))
newimg.setFilename('c:/myimage.png')
newimg.save()
This creates a 2kb file called myimage.png on the disk but the image can’t be viewed in any viewer i’ve tried. Judging by the content of the file, it doesn’t seem to be png either but rather some raw data.
What am I doing wrong?
replacing Image.New() with Image.Load() works fine, but the idea is that I’m supposed to create the image myself.
Looking at the BPy source, it appears the file type is not getting set. ( the type is not the same thing as the file extension, no matter what some OSes assume).
Your next question, no doubt, is “How to set the file type?” Sadly, that seems to be something missing from the Image module.
Anticipating your next question, I can only assume whoever implemented the Image module cared more about loading images than creating them from scratch.
I simply made the mistake of assuming Blender would set the format based on the file extension.
I’ve tried opening the file in Gimp(which handles targa) but Gimp seems to go by the file extension and therefore identified the image as a png.
Changed the file extension to .tga and the problem was solved.