Optimizes RAM consumption by unloading images from the DPG.
It works quite simply: if the image is visible it is loaded, if not visible then after a certain amount of time is unloaded from the DPG
0.mp4
1255 images with 1920×1080 resolution were used
You can try this example using this script: example.py
-
Download the library(
git clone https://github.com/IvanNazaruk/DearPyGui-ImageController
) and move theDearPyGui_ImageController
folder to your project/script -
Import the library:
import DearPyGui_ImageController as dpg_img
- Set DPG texture registry:
dpg_img.set_texture_registry(dpg.add_texture_registry())
- Add the image:
dpg_img.add_image("{IMAGE_PATH}")
Or use Pillow:
from PIL import Image
img = Image.open("{IMAGE_PATH}")
dpg_img.add_image(img)
import dearpygui.dearpygui as dpg
import DearPyGui_ImageController as dpg_img
dpg.create_context()
dpg_img.set_texture_registry(dpg.add_texture_registry())
with dpg.window():
dpg_img.add_image("{IMAGE_PATH}")
# from PIL import Image
# img = Image.open("{IMAGE_PATH}")
# dpg_img.add_image(img)
dpg.create_viewport()
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
Use the internal functions set_width
, set_height
and set_size
. If width or height is not specified, the other dimension will be decreased/increased proportionally. If the dimensions are not set, the image size will be used.
An example use case is found in example.py:
First we will save the created image viewer object:
DearPyGui-ImageController/example.py
Lines 21 to 22 in 5866e1d
DearPyGui-ImageController/example.py
Lines 33 to 34 in 5866e1d
Use the internal function set_image_handler
. Example usage:
with dpg.item_handler_registry() as image_handler:
dpg.add_item_clicked_handler(callback=lambda _, data: print(f"Clicked: {data[0]}"))
image_viewer = dpg_img.add_image("{IMAGE_PATH}")
image_viewer.set_image_handler(image_handler)
- Increase documentation
- GIFs support