saveImageDataToFile(color_and_alpha_data, width, height, file_name)
Either a sequence of floats or a binary string containing the image data. The data must be in interleaved format, meaning that the first 4 values are the red, green, blue, and alpha (RGBA) values for the first pixel, the next 4 are for the second pixel, and so on. The first row of pixels in the data corresponds to the top scanline in the image.
The length of this sequence must be
width * height * 4.
If you are writing a
.pic file, the file will store 32-bit float data
if you pass in a sequence of floats and 8-bit unsigned data if you pass
in a string.
The binary string data must be a
bytes object in Python 3 and a
object in Python 2. See HOM binary data for more
The width and height of the image to be written.
The name of the output image file to create. Houdini will automatically determine which type of file to create based on this file’s extension.
This function provides two features not provided by other imaging libraries:
It lets you create files in Houdini’s
It lets you save images with 32-bit float data.
Raises hou.OperationFailed if the data is not the correct size, the output file could not be created, or the output file format is not supported by Houdini.
The following example uses the Python imaging library (PIL) to read in a file
and calls this function to write it out. Using the
below, you can convert any image that can be read by PIL into Houdini’s
import Image def convertImage(input_image, output_image): im = Image.open(input_image) im.mode != "RGBA": raise ValueError("The image must contain alpha information") hou.saveImageDataToFile(im.tostring(), im.size, im.size, output_image) convertImage("image.png", "image.pic")
See also Writing a COP in Python.