2017-10-27 6 views
0

내가 4 개 픽셀 이미지를 만들려고하고있는 지팡이 이미지를 만들 수 있습니다 화이트 색상의어떻게 파이썬

코드 :

import wand.image 

red = wand.image.Color('rgb(255,0,0)') 
green = wand.image.Color('rgb(0,255,0)') 
blue = wand.image.Color('rgb(0,0,255)') 
white = wand.image.Color('rgb(255,255,255)') 

myImage = wand.image.Image(width=2,height=2) 

with wand.image.Image (myImage) as img: 
    img[0][0] = red 
    img[0][1] = blue 
    img[1][0] = green 
    img[1][1] = white 
    img.save(filename='out.png') 

그러나 그것은 단지 투명한 png 만듭니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

1

완드의 픽셀 반복기는 색상 데이터를 ImageMagick의 "본격적인"픽셀 데이터 - 증기로 "동기화"하는 기능이 부족합니다.

like this question 가져 오기 - 픽셀 데이터 스트림을 구현할 수 있습니다 (비슷한 질문을 많이 받는다).

또는 wand.drawing.Drawing API를 사용하십시오.

from wand.image import Image 
from wand.drawing import Drawing 
from wand.color import Color 


with Drawing() as ctx: 
    colors = ["RED", "GREEN", "BLUE", "WHITE"] 
    for index, color_name in enumerate(colors): 
     ctx.push()       # Grow context stack 
     ctx.fill_color = Color(color_name) # Allocated color 
     ctx.point(index % 2, index/2) # Draw pixel 
     ctx.pop()       # Reduce context stack 
    with Image(width=2, height=2, background=Color("NONE")) as img: 
     ctx.draw(img) 
     img.sample(100,100) 
     img.save(filename="output.png") 

output.png

+0

생명의 은인, 들으 – Tom