PIL Tkinter Canvas EPS to PNG conversion output file contains issues

元气小坏坏 提交于 2019-12-24 15:56:19

问题


So I have created the following save function for my turtle graphics program to allow the user to save the canvas as a .png file with its own file name:

def savefirst():
    cnv = getscreen().getcanvas() 
    ps = cnv.postscript(colormode = 'color')
    hen = filedialog.asksaveasfilename()
    print(hen)
    im = Image.open(io.BytesIO(ps.encode('utf-8')))
    im = im.resize((2560, 1600), Image.ANTIALIAS)
    quality_val = 95
    sharp = ImageEnhance.Sharpness(im)
    sharp.enhance(2.0).save(hen + '.png', 'PNG')

However, if the user were to set the background to a different color, in the output file (.png) the background color does not appear. Also, the output image gets VERY rough around curves. Below is what I mean, according to a screenshot of the canvas itself comparing it to the saved output:

Screen shot of Canvas itself:

Saved Output:

How would I fix these issues, preferably somehow using the Python Imaging Library? If that is not possible, is there ANY other way for me to save my canvas as a jpeg so that EVERYTHING comes out flawless (just as a screenshot, i.e. with ALL the colors and NO distortions)? Any help is very much appreciated!

来源:https://stackoverflow.com/questions/34821534/pil-tkinter-canvas-eps-to-png-conversion-output-file-contains-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!