Is it possible to scale an image/texture? #1789
-
Hello, I would like to be able to scale an image, but I don't see a way to do this with the API. Is there a way to do this either at load time ( Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I figured out how to do this. You just need to change the width and height in the
Would scale to 40% original size for example. |
Beta Was this translation helpful? Give feedback.
-
def add_and_load_image(image_path, parent=None , scale=0.4):
width, height, channels, data = dpg.load_image(image_path)
with dpg.texture_registry() as reg_id:
texture_id = dpg.add_static_texture(width, height, data, parent=reg_id)
if parent is None:
return dpg.add_image(texture_id,width=width*scale, height=height*scale)
else:
return dpg.add_image(texture_id, parent=parent , width=width*scale, height=height*scale) |
Beta Was this translation helpful? Give feedback.
I figured out how to do this. You just need to change the width and height in the
add_image
call, not in theadd_static_texture
call. If you scale both height and width by the same factor you'll get the scaling you want.dpg.add_image("texture_tag", width=int(dpg.get_item_width("texture_tag") * 0.4), height=int(dpg.get_item_height("texture_tag") * 0.4))
Would scale to 40% original size for example.