0
我試圖生成一些分形圖像,我可以做得很好。但是,在保存圖像時,我遇到了一些問題,因爲它將它們保存爲灰度而不是顏色。當我用python打開它們時,它顯示正確的顏色。PIL圖像保存爲灰度
的代碼如下
from PIL import Image
import ImageDraw
from scipy import misc
from array import *
import matplotlib.pyplot as plt
import scipy
image = Image.new("L",(SIZE, SIZE)) # create a image SIZE x SIZE
d = ImageDraw.Draw(image)
#iterate over x and y, setting a col value for each pixel
d.point((x, y), col) # it then colors the point (x,y)
image.save("beta"+str(alpha)+".png", "PNG")
我使用MacOS X系統,Python的2.7.5。
嗯,我正在調整代碼,但更新col值,我只是將它設置爲一個不同的整數值。我將研究使用RGB。那我到底應該怎樣定義col?只是(價值,價值,價值)的元組? –
@DanielAbramovici:是的,一個元組可以。有關其他支持的值,請參閱[ImageDraw文檔](http://effbot.org/imagingbook/imagedraw.htm)。 –
你實際上也可以使用一個整數。我在這裏問完全問題(使用整數的彩色圖像):http://stackoverflow.com/questions/32192671/pil-image-mode-i-is-grayscale/32200857 – Miguel