I am trying to use Pysimplegui and its "graph" component to make an app such that the user can draw polygons on an image using the app. Here is a part of my code:
layout = [[sg.Graph(
canvas_size=(length, width),
graph_bottom_left=(0, 0),
graph_top_right=(length, width),
key="-GRAPH-",
change_submits=True, # mouse click events
background_color='lightblue',
drag_submits=True), ],]
window = sg.Window("draw rect on image", layout, finalize=True)
graph = window["-GRAPH-"]
Here length and width refers to the size of image I have. The only way which I know how to display the image is via graph.draw_image(path, location=(0,width))
, where the path is the location of an png file.
My question is: Is there a way to display an image in graph that uses directly the image and not a path. (i.e. If I have an nd numpy array that represents an image, is it possible for me to directly make it show up in the canvas rather than first save as png then load the location?). Is it possible to avoid any kind of saving at all?
Intuitively, the method graph.draw_image
reads the path and opens the image and then displays. There should be a method to avoid any saving and make graph directly display an image.