Jump to content
  • Advertisement
Sign in to follow this  
Radiocreed

Storing image file in Python PIL as an unsigned char*

This topic is 4960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to convert an image file data from Python PIL to an unsigned char*. Here's how i read the image data from python: im = PIL.open( filename ) data = list( im.getdata() ) Now, i want this data in unsigned char* so that i can use it in my c++ codes for texture mapping, any help please?

Share this post


Link to post
Share on other sites
Advertisement
Look for array in the python-docs


from array import array
import Image

im = Image.open("test.bmp" )
data = list( im.getdata() )

#here is your data as an array of unsigned char
outdata=array('B',data)

#let's write it to a file
f=open("imagedata",'wb')
outdata.tofile(f)
f.close()


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!