Search code examples
androidapp-inventor

AppInventor 2: resize image (Canvas) proportionally to fill the space


I have Canvas with BackgroundImage (selected by user) that should fill all available space.

enter image description here

But if I set Canvas Height/Width to Fill it becomes simply stretched non-proportionally.

And with Automatic it's too small for some reason, much smaller than the original image (tested in Genymotion emulator and on OnePlus 3T with Android 8, in both screen orientations).

enter image description here

Is it possible to resize it to max possible size while keeping the aspect ratio?

It would be easy if I could get the image size in blocks, but I don't see any way to do it. I also tried to use Canvas Width/Height but looks like they are not updated immediately after setting the image (during screen initialization) and I don't see any other events.


Solution

  • Solved it using Clock (timer with small interval, such as 100).

    It seems to work as expected on the image from my question (1920x1080). However on some images I noticed strange issues with quality, like it was a small image resized to much bigger size (especially noticeable on images containing text) even though it works fine in other viewers. But it's probably not related to this resizing (I even tried to clear and set BackgroundImage again after resizing), here is a similar report: https://groups.google.com/forum/#!topic/mitappinventortest/_Iro4UKNE1Q