Incorrect converting from PIL image to DearPyGUI image

138 Views Asked by At

I read somewhere how to convert a PIL image into a DearPyGUI image. The idea is that the user specifies the path to the png-image, the program opens it as a PIL-image and then displays it (as a dynamic texture) in DearPyGUI. So, for some reason, the entire texture is white, you can also see some artifacts.

I tried this code:

def fileOpened(sender, app_data, user_data):
    image_dir = app_data['file_path_name']
    image = Image.open(image_dir)
    image.thumbnail((500, 500), Image.ANTIALIAS)
    image_data = list(image.getdata())
    image_dpg = []
    for i in range(image.width * image.height):
        image_dpg.append(float(image_data[i][0]))
        image_dpg.append(float(image_data[i][1]))
        image_dpg.append(float(image_data[i][2]))
        try:
            image_dpg.append(float(image_data[i][3]))
        except:
            image_dpg.append(255.0)
    dpg.set_value("canvas_default", image_dpg)

Program:

enter image description here

Input image:

enter image description here

0

There are 0 best solutions below