A
A
Andrei1penguin12021-05-14 00:12:35
Python
Andrei1penguin1, 2021-05-14 00:12:35

How to sync rectangle with image?

Good day, there is a task:
There is a Widget with fixed sizes, it has a BoxLayout, this same BoxLayout should be the maximum allowable size, that is, either the height, like a widget, or the width, or both.
The background in this BoxLayout is a picture , and it’s random
And the whole problem is that the aspect ratio of the widget is always the same, and the pictures are different, therefore, you need to make sure that the dimensions of the BoxLayout nested in the widget adapt to the picture
For example:
Let the widget be 2000x1000
Picture 300x100, picture is placed in the BoxLayout and stretched along with it
. Since the image has a larger width, we make the width equal to the width of the widget, that is, 2000
Accordingly, the height of the picture should increase in proportion: 100 * (2000 / 300) = 100 * 6.(6) = 666.(6)
If there was work with some kind of opencv, all the logic would be written through resize without any problems, but after all, kivy resizes the image under the hood and does not provide any API for working with it.
It is clear that you can first measure the image, create a copy of it, place it in a widget, delete this copy after closing the application (the original image cannot be changed), but this is unseen crutch sizes
Are there any harmonious solutions, maybe even using kivy?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question