我正在尝试使用PIL保存我从头开始创建的图像
newImg1 = PIL.Image.new('RGB', (512,512))
pixels1 = newImg1.load()
...
for i in range (0,511):
for j in range (0,511):
...
pixels1[i, 511-j]=(0,0,0)
...
newImg1.PIL.save("img1.png")
我遇到了以下错误:
Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 523, in runfile execfile(filename, namespace) File "C:\Python27\Lib\site-packages\xy\pyimgmake.py", line 125, in newImg1.PIL.save("img1.png") File "C:\Python27\lib\site-packages\PIL\Image.py", line 512, in getattr raise AttributeError(name) AttributeError: PIL
我需要帮助理解这个错误以及如何正确保存图片为“img1.png”(将图片保存到默认保存位置也可以)。
更新:
from PIL import Image as pimg
...
newImg1 = pimg.new('RGB', (512,512))
...
newImg1.save("img1.png")
我收到以下错误信息:
... newImg1.save("img1.png") File "C:\Python27\lib\site-packages\PIL\Image.py", line 1439, in save save_handler(self, fp, filename) File "C:\Python27\lib\site-packages\PIL\PngImagePlugin.py", line 572, in _save ImageFile._save(im, _idat(fp, chunk), [("zip", (0,0)+im.size, 0, rawmode)]) File "C:\Python27\lib\site-packages\PIL\ImageFile.py", line 481, in _save e = Image._getencoder(im.mode, e, a, im.encoderconfig) File "C:\Python27\lib\site-packages\PIL\Image.py", line 399, in _getencoder return apply(encoder, (mode,) + args + extra) TypeError: an integer is required
newImg1.PIL.save("img1.png")
дёзљ„PIL.
移除,然后尝试执行。 - Srinivas Reddy Thatiparthy