I can't add an image with "dearpygui" HELP!

hello! i’m working on app and i want to add an image , but i can’t
i used this functions : add_static_texture() | add_image()
After running this application which is written by console:

Traceback (most recent call last): File "D:\Games\apps\app1\app.py", line 48, in <module> texture_id = dpg.add_static_texture(width, height, image_data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\d info\AppData\Roaming\Python\Python311\site-packages\dearpygui\dearpygui.py", line 7023, in add_static_texture return internal_dpg.add_static_texture(width, height, default_value, label=label, user_data=user_data, use_internal_label=use_internal_label, tag=tag, parent=parent, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SystemError: <built-in function add_static_texture> returned a result with an exception set

and this is script:

image_path = "1032.png"
width, height = 512, 512
with open(image_path, "rb") as f:
     image_data = f.read()
with dpg.handler_registry():
     texture_id = dpg.add_static_texture(width, height, image_data)
with dpg.handler_registry():
     dpg.add_image(texture_id, width=512, height=512)

tell me here!

The script is not complete, for example dpg is not defined.
Provide a complete, small, example that shows the problem please.

2 Likes

yeah i know i difined it import dearpygui.dearpygui as dpg and console show that error in this clip

image_path = "1032.png"
width, height = 512, 512
with open(image_path, "rb") as f:
     image_data = f.read()
with dpg.handler_registry():
     texture_id = dpg.add_static_texture(width, height, image_data)
with dpg.handler_registry():
     dpg.add_image(texture_id, width=512, height=512)

It looks like what you’re doing is causing an error somewhere inside the module, an error that the module is ignoring.

It shouldn’t ignore the error.

Please report it to the package’s maintainers.

ok ill report this error but do you have another way to add image?

This works:

import dearpygui.dearpygui as dpg

dpg.create_context()

image_path = "1032.png"

width, height, channels, image_data = dpg.load_image(image_path)

with dpg.texture_registry():
    texture_id = dpg.add_static_texture(width=width, height=height, default_value=image_data)

with dpg.window():
    dpg.add_image(texture_id)

dpg.create_viewport(title='Custom Title', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()

If I use dpg.add_image in the dpg.handler_registry() context, it crashes.

If I leave out dpg.create_context(), it quits Python unexpectedly.

The package needs some more robust error handling.

thank you for help it work :grin: