1

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

num3ri
  • 822
  • 16
  • 20
KuraKur
  • 11
  • 3
  • 1
    I don't know/use DearPyGUI, but many libraries that use `float` values scale them on a range of 0..1, whereas PIL uses a range of 0..255, so you may need to divide the PIL values by 255.0. – Mark Setchell Apr 04 '23 at 21:29
  • Any special reason, why not to use [loadImage](https://dearpygui.readthedocs.io/en/latest/reference/dearpygui.html#dearpygui.dearpygui.load_image) function of dearpygui? – guidot May 02 '23 at 10:34

0 Answers0