2017-11-16 16 views
2

tupledlist=[(71, 146, 110), (71, 146, 98), (71, 146, 99), (71, 146, 109), (71, 146, 26), (71, 146, 99), (71, 146, 109), (71, 146, 26), (71, 146, 91), (71, 146, 26), (71, 146, 110), (71, 146, 95), (71, 146, 109), (71, 146, 110), (71, 146, 26), (71, 146, 103), (71, 146, 95), (71, 146, 109), (71, 146, 109), (71, 146, 91), (71, 146, 97), (71, 146, 95), (71, 146, 26), (71, 146, 91), (71, 146, 104), (71, 146, 94), (71, 146, 26), (71, 146, 110), (71, 146, 98), (71, 146, 99), (71, 146, 109), (71, 146, 26), (71, 146, 99), (71, 146, 109), (71, 146, 26), (71, 146, 91), (71, 146, 26), (71, 146, 110), (71, 146, 95), (71, 146, 109), (71, 146, 110), (71, 146, 26), (71, 146, 102), (71, 146, 99), (71, 146, 109), (71, 146, 110)]タプルのリストから作成されたpng画像をそのタプルのリストに戻す方法は?

from PIL import Image 
OUTPUT_IMAGE_SIZE = (1280, 720) 
for frame_number, color in enumerate(tupledlist): 
    image = Image.new('RGB', OUTPUT_IMAGE_SIZE, color=color) 
    image.save("path.png") 

これは、PNGイメージを作成します。今度は、画像からタプルのリストを戻したい。これを達成する方法は?私はmage.getbands()を試しましたが、動作しません。

import PIL 
from PIL import Image 
image=Image.open("c:/users/ashub/desktop/encrypted.png") 
image.getbands() 
+0

'list(image.getdata())'を試してください。詳細はこちら[こちら](http://effbot.org/imagingbook/image.htm#tag-Image.Image.getdata)をご覧ください。 –

+0

私はそれを試してみましたが、うまくいきません。 – Demonking28

+0

あなたはどんな出力を得ていますか? –

答えて

4

私が正しく理解していれば、あなたはこれを達成したい:(RGB値で

from PIL import Image 

tupledlist=[(71, 146, 110), (71, 146, 98), (71, 146, 99), (71, 146, 109), (71, 146, 26), (71, 146, 99), (71, 146, 109), (71, 146, 26), (71, 146, 91), (71, 146, 26), 
      (71, 146, 110), (71, 146, 95), (71, 146, 109), (71, 146, 110), (71, 146, 26), (71, 146, 103), (71, 146, 95), (71, 146, 109), (71, 146, 109), (71, 146, 91), (71, 146, 97), 
      (71, 146, 95), (71, 146, 26), (71, 146, 91), (71, 146, 104), (71, 146, 94), (71, 146, 26), (71, 146, 110), (71, 146, 98), (71, 146, 99), (71, 146, 109), (71, 146, 26), 
      (71, 146, 99), (71, 146, 109), (71, 146, 26), (71, 146, 91), (71, 146, 26), (71, 146, 110), (71, 146, 95), (71, 146, 109), (71, 146, 110), (71, 146, 26), (71, 146, 102), 
      (71, 146, 99), (71, 146, 109), (71, 146, 110)] 

OUTPUT_IMAGE_SIZE = (1280, 720) 
image = Image.new('RGB', OUTPUT_IMAGE_SIZE) 
image.putdata(tupledlist) 
image.save("path.png") 
print("Saved image.") 

image=Image.open("path.png") 
print(list(image.getdata())) 

リストがイメージに保存されますが、残りのピクセルの残りの部分は、RGB値をとります0,0,0)。それらを印刷すると、すべての921600(1280x720)ピクセルが表示されます。

関連する問題