Hello. I managed to get away with updating a raw texture with different size by only deleting the texture item and the draw_image item, without deleting the window item. The window itself can be resized without crashing at all, so before re-calling draw_image I resize the window with configure_item. Changing the width or height of the raw texture item always resulted in a crash for me or sometimes in the texture showing completely random data.
setup:
# NOTE: This is not the complete setup. Before any of this, dpg.create_context should be called, as well as dpg.create_viewport()
# And after this code, dpg.setup_dearpygui(), dpg.show_viewport(), dpg.start_dearpygui() or the dpg.render_dearpygui_frame() (only use this function if doing this in a loop)
with dpg.texture_registry():
z = np.zeros((700, 700, 4), dtype=np.float32 )
dpg.add_raw_texture(tag="texture_cropped_optical_tag", width=700, height=700, format=dpg.mvFormat_Float_rgba, default_value=z)
with dpg.window(label="CROP", tag="cropped_optical_window"):
dpg.draw_image(tag="draw_ttt", texture_tag="texture_cropped_optical_tag", pmin=[0,0], pmax=[700,700])
my callback function to a button. this is where the deletion and recreation of items is done:
def button_send_crop_layer(self, sender, app_data, user_data):
rectangle = self.rectangle(layer_index=user_data["layer_index"])
startx, starty = rectangle["pmin"][0], rectangle["pmin"][1]
endx, endy = rectangle["pmax"][0], rectangle["pmax"][1]
startx = int(startx)
starty = int(starty)
endx = int(endx)
endy = int(endy)
frame = self.frame.copy()
print()
print(startx)
print(starty)
print(endx)
print(endy)
print()
cropped_frame = ImageTransformer.frame_crop_frame(frame, startx, starty, endx, endy)
height, width, _ = cropped_frame.shape
dpg.delete_item("texture_cropped_optical_tag")
dpg.delete_item("draw_ttt")
with dpg.texture_registry():
#z = np.zeros((height, width, 4), dtype=np.float32)
z = cropped_frame
z = ImageTransformer.frame_bgr_to_rgba_normalized(z)
dpg.add_raw_texture(tag="texture_cropped_optical_tag", width=width, height=height,
format=dpg.mvFormat_Float_rgba, default_value=z)
dpg.configure_item("cropped_optical_window", width=width+10, height=height+10)
dpg.draw_image(parent="cropped_optical_window" ,tag="draw_ttt", texture_tag="texture_cropped_optical_tag", pmin=[0, 0], pmax=[width, height])