I'm not exactly sure what you want to accomplish by doing this, but here's a working example of saving the raw image pixel data into a file, reading it back, and then creating anImage
object out of it again.
It's important to note that for compressed image file types, this conversion will expand the amount of memory required to hold the image data since it effectively decompresses it.
from PIL import Image
png_image = Image.open('input.png')
saved_mode = png_image.mode
saved_size = png_image.size
# write string containing pixel data to file
with open('output.data', 'wb') as outf:
outf.write(png_image.tostring())
# read that pixel data string back in from the file
with open('output.data', 'rb') as inf:
data = inf.read()
# convert string back into Image and display it
im = Image.fromstring(saved_mode, saved_size, data)
im.show()