sheb
01-09-2008, 06:10 AM
Hello,
I'm trying to use Python and the API to write out an imagefile (that i want to draw myself).
Somehow I cannot pass my pixel array to the MImage object - I don't know why it is not working. Whatever I pass it results in 1's only. Here is my code:
import random
import maya.OpenMaya as om
img = om.MImage()
img.create(100,100,4,1)
pix=[]
#make some test data
for i in range(1,10000) :
c= random.randint(1, 255)
pix+= [c,c,c,1]
#print pix
#Pass to MImage as a Pointer
p = om.MScriptUtil()
p.createFromList(pix,40000)
img.setPixels(p.asUcharPtr(), 100, 100)
#Reading for testing
ga=[]
r = om.MScriptUtil()
ret = img.pixels()
for i in range(1,40000): ga.append(r.getUcharArrayItem(ret,i))
print ga # prints out a bunch of 1's
img.writeToFile("d:\\test.iff","iff")
Thanks for any hints - its the first time i'm using something from the api, maybe i got something wrong..
seb
I'm trying to use Python and the API to write out an imagefile (that i want to draw myself).
Somehow I cannot pass my pixel array to the MImage object - I don't know why it is not working. Whatever I pass it results in 1's only. Here is my code:
import random
import maya.OpenMaya as om
img = om.MImage()
img.create(100,100,4,1)
pix=[]
#make some test data
for i in range(1,10000) :
c= random.randint(1, 255)
pix+= [c,c,c,1]
#print pix
#Pass to MImage as a Pointer
p = om.MScriptUtil()
p.createFromList(pix,40000)
img.setPixels(p.asUcharPtr(), 100, 100)
#Reading for testing
ga=[]
r = om.MScriptUtil()
ret = img.pixels()
for i in range(1,40000): ga.append(r.getUcharArrayItem(ret,i))
print ga # prints out a bunch of 1's
img.writeToFile("d:\\test.iff","iff")
Thanks for any hints - its the first time i'm using something from the api, maybe i got something wrong..
seb
