I've opened an image in PIL like so:
from PIL import Image
i = Image.open("image.jpg")
I need to access the raw contents of this file. How can I get the entire picture data, as if I would have done open(...).read()?
I've opened an image in PIL like so:
from PIL import Image
i = Image.open("image.jpg")
I need to access the raw contents of this file. How can I get the entire picture data, as if I would have done open(...).read()?
PIL uses a lazy opening mechanism, in which the file contents are only read when needed. For doing that, it probably keeps the file reference in some internal (private) attribute.
Even if this attribute is accessible, it certainly is not exposed as part of the official PIL API - and it certainly is not meant to be used in this way.
Once the data is read, the file contents are decoded, and kept in memory as pixel values (which is usually what is desired when dealing with images). The library certainly does not keep the undecoded file data in a data structure in memory, as it would be meaningless.
If you want the raw file contents, you are likely processing the image with some other module, or storing it, or iterating over the data in a form that is agnostic to the actual image contents - can't you just open the file back with a regular "open"?
更多推荐
所有评论(0)