Try to do some image processing, load an image to show on Graph, but nothing shown. Win10 / Python 3.7.6 / PySimpleGUI 4.16.0 / Numpy 1.18.1
I Load an image by PIL.Image, convert it to numpy array, then to base64, DrawImage in Graph, but show nothing. I had been work on it for serveral times and all OK. checked it for couple hours, but nothing help. Can someone help me to figure out where I missed or wrong ?
Something I found,
- im open, im.show() OK
- im.shape is correct, for example (200, 150, 3) for an 150 (width) x 200 (height) x RGB image.
- im_np shown different data, it seems OK.
- im_64 shown the byte string
- draw is None, it should be a id.
- with filename option set for DrawingImage, it is OK
I need to using numpy for some image process here, so conversion is required.
import base64
import numpy as np
import PySimpleGUI as sg
from PIL import Image
filename = 'D:/Disk.png'
im = Image.open(filename)
width, height = im.size
im_np = np.array(im) # It is necesary for future process
im_64 = base64.b64encode(im_np)
def Graph(key):
return sg.Graph(im.size, graph_bottom_left=(0, 0),
graph_top_right=(width, height), key=key)
layout = [[Graph('GRAPH')]]
window = sg.Window('Graph', layout=layout, finalize=True)
draw = window.FindElement('GRAPH').DrawImage(
data=im_64, location=(width/2, height/2)) # It failed
# filename=filename, location=(width/2, height/2)) # It working well
while True:
event, values = window.read()
if event == None:
break
window.close()