V
V
Vadim Prokhorov2017-07-06 05:42:42
Android
Vadim Prokhorov, 2017-07-06 05:42:42

How to calculate required width and height of two images?

Yes tableRow, two are placed in it ImageView. Photos are ImageViewuploaded in various sizes. It is necessary to change the scale of each photo (fit to the same height) (example below)
bbb3549506f34b8ab862ca505dbe4a58.PNG
There are no problems with photos of the same size, I do everything as follows:

  1. Let's say images width and height = 454x807
  2. We find the coefficient. scale. - 807 / 454 = 1.77
  3. Finding the sum of the widths of two images - 908
  4. The screen of the device, let's say = 1080, and since our images in total are less than 1080, then they need to be stretched (it would be more, they would narrow)
  5. 1080 - 908 = 172, divide this number by the number of images, that is, by 2 = 86
  6. We add to the width of each photo the resulting number - 454 + 86 = 540
  7. And we find its new height - 540 * 1.77 = 959.8 (the average of the two heights)

Everything seems to be fine, the new width is known, the height is the same. Everything is great, but when using photos from the image above (1 photo - 135x807, 2 photos - 807x605), everything does not happen as we would like (in the end I want to get what is in the image above - the approximate height is 717, the first photo is 121 in width and the second 959 in width (this number was achieved by visual comparison of my "creation" with the original))
How can I finally make the whole thing scale normally?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2017-07-06
@Vadik052

There are 2 images with width and height values ​​(w1,h1) and (w2,h2). The total width of two images after transformation is known: W.
It is required to find the coefficients k1 and k2 of proportional scaling of two images so that the modified images:
Solve this system of equations. I managed

k1 = W / ( w2 * ( h1/h2 + w1/w2))
k2 = k1 * (h1/h2)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question