PIL:Imageobject.save() 在绘制完全损坏的图像并模糊输出之后
PIL: Imageobject.save() after drawing completely corrupts images and smurfs the ouput
我的程序中有这两个函数:
def depict_ph_increase(x,y,color, imobject):
program_print(color)
draw = PIL.ImageDraw.Draw(imobject)
draw.text((x, y),color,(255,255,255))
imobject.save('tmp-out.gif')
im_temp = PIL.Image.open("tmp-out.gif")#.convert2byte()
im_temp = im_temp.resize((930, 340), PIL.Image.ANTIALIAS)
MAP_temp = ImageTk.PhotoImage(im_temp)
map_display_temp = Label(main, image=MAP_temp)
map_display_temp.image = MAP_temp # keep a reference!
map_display_temp.grid(row=4,column=2, columnspan=3)
def read_temp_pixels(temperature_file, rngup, rngdown):
temp_image_object = PIL.Image.open(temperature_file)
(length, width) = get_image_size(temp_image_object)
(rngxleft, rngxright) = rngup
(rngyup,rngydown) = rngdown
print 'the length and width is'
print length, width
hotspots = 5;
for hotspot in range(0,hotspots):
color = "#ffffff"
while color == "#ffffff" or color == "#000000" or color == "#505050" or color == "#969696":
yc = random.randint(rngxleft, rngxright)
xc = random.randint(rngyup,rngydown)
color = convert_RGB_HEX(get_pixel_color(temp_image_object, xc, yc))
depict_ph_increase(xc,yc,color, temp_image_object)
下一个叫上一个。他们的工作是阅读这张图片:
然后它随机选择几个像素,抓取它们的颜色,并将颜色的十六进制值写在顶部。但是,当它重新显示图像时,它给了我这个垃圾:
靠近右上角的那些白色数字是其绘图的十六进制值。它以某种方式从损坏的图像中读取值,尽管事实上我在实际调用 ImageDraw()
方法之后才收集这些值。有人可以向我解释为什么它会损坏图像吗?
一些背景--get_pixel_color()
函数在程序中多次使用并且非常准确,它只是以某种方式从新损坏的图像中读取像素数据。此外,我在我的代码中的其他地方进行类似的图像读取(但不写入)。
如果有什么我可以澄清的,或者您想查看我的代码的任何其他部分,请告诉我。您还可以在我的 github 此处查看完整的程序:https://github.com/jrfarah/coral/blob/master/src/realtime.py 它应该是提交 #29。
我检查过的其他 SO 问题无济于事:Corrupted image is being saved with PIL
如有任何帮助,我们将不胜感激!
我通过编辑此行解决了问题:
temp_image_object = PIL.Image.open(temperature_file)
成为
temp_image_object = PIL.Image.open(temperature_file).convert('RGB')
我的程序中有这两个函数:
def depict_ph_increase(x,y,color, imobject):
program_print(color)
draw = PIL.ImageDraw.Draw(imobject)
draw.text((x, y),color,(255,255,255))
imobject.save('tmp-out.gif')
im_temp = PIL.Image.open("tmp-out.gif")#.convert2byte()
im_temp = im_temp.resize((930, 340), PIL.Image.ANTIALIAS)
MAP_temp = ImageTk.PhotoImage(im_temp)
map_display_temp = Label(main, image=MAP_temp)
map_display_temp.image = MAP_temp # keep a reference!
map_display_temp.grid(row=4,column=2, columnspan=3)
def read_temp_pixels(temperature_file, rngup, rngdown):
temp_image_object = PIL.Image.open(temperature_file)
(length, width) = get_image_size(temp_image_object)
(rngxleft, rngxright) = rngup
(rngyup,rngydown) = rngdown
print 'the length and width is'
print length, width
hotspots = 5;
for hotspot in range(0,hotspots):
color = "#ffffff"
while color == "#ffffff" or color == "#000000" or color == "#505050" or color == "#969696":
yc = random.randint(rngxleft, rngxright)
xc = random.randint(rngyup,rngydown)
color = convert_RGB_HEX(get_pixel_color(temp_image_object, xc, yc))
depict_ph_increase(xc,yc,color, temp_image_object)
下一个叫上一个。他们的工作是阅读这张图片:
然后它随机选择几个像素,抓取它们的颜色,并将颜色的十六进制值写在顶部。但是,当它重新显示图像时,它给了我这个垃圾:
靠近右上角的那些白色数字是其绘图的十六进制值。它以某种方式从损坏的图像中读取值,尽管事实上我在实际调用 ImageDraw()
方法之后才收集这些值。有人可以向我解释为什么它会损坏图像吗?
一些背景--get_pixel_color()
函数在程序中多次使用并且非常准确,它只是以某种方式从新损坏的图像中读取像素数据。此外,我在我的代码中的其他地方进行类似的图像读取(但不写入)。
如果有什么我可以澄清的,或者您想查看我的代码的任何其他部分,请告诉我。您还可以在我的 github 此处查看完整的程序:https://github.com/jrfarah/coral/blob/master/src/realtime.py 它应该是提交 #29。
我检查过的其他 SO 问题无济于事:Corrupted image is being saved with PIL
如有任何帮助,我们将不胜感激!
我通过编辑此行解决了问题:
temp_image_object = PIL.Image.open(temperature_file)
成为
temp_image_object = PIL.Image.open(temperature_file).convert('RGB')