[英]PIL image conversion not using file system
I would like to do image conversion/rewriting with PIL just using RAM memory. 我想仅使用RAM内存使用PIL进行图像转换/重写。 I have the image in bytes in RAM and I would like to convert it to some other format or possibly the same.
我将图像以字节为单位存储在RAM中,我想将其转换为其他格式或可能相同。 I know I can do it like saving it in on the file system with some name, but I would like to do it just using RAM without touching the file system.
我知道我可以像将其保存在文件系统中那样命名,但是我只想使用RAM而不接触文件系统即可。 I haven't found any examples.
我还没有找到任何例子。 Any help would be appreciated!
任何帮助,将不胜感激! Thanks!
谢谢!
You can use a StringIO
file object instead of a regular file as well with both PIL Image.open
and Image.save
您还可以将
StringIO
文件对象而不是常规文件与PIL Image.open
和Image.save
# somewhere earlier in the code:
# data = ...
from StringIO import StringIO
fd = StringIO(data)
image = Image.open(fd)
image.show()
There's also a frombuffer
function 还有一个
frombuffer
函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.