V
V
Vadim Prokhorov2017-08-05 15:28:46
Android
Vadim Prokhorov, 2017-08-05 15:28:46

How to find required width and height of three images?

There is a tableRow, three ImageViews are placed in it. The ImageView is loaded with photos of various sizes. It is necessary to rescale each photo (fit to the same height) while respecting the correct width of the images.
I already asked a similar question on this resource, only for two images: link
As a result, for two images I got the following:

float image1Width = Utils.getDownloadedImageWidth(post, indexImage1);
float image2Width = Utils.getDownloadedImageWidth(post, indexImage2);
float image1Height = Utils.getDownloadedImageHeight(post, indexImage1);
float image2Height = Utils.getDownloadedImageHeight(post, indexImage2);
float scale = Math.max(image1Height, image2Height);
float newImage1Width = (scale / image1Height) * image1Width;
float newImage2Width = (scale / image2Height) * image2Width;
float k1 = MainActivity.SCREEN_WIDTH / (image2Width * (image1Height / image2Height + image1Width / image2Width));
float k2 = k1 * (image1Height / image2Height);
float tempHeight1 = k1 * image1Height;
float tempHeight2 = k2 * image2Height;
float tempHeight = Math.max(tempHeight1, tempHeight2);

Where tempHeight is the desired height and newImage1Width and newImage2Width are the width.
How can this algorithm be modified for three images?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2017-08-05
@Vadik052

W is the width of the area in which the set of images should be entered
. H is the height of the area.
For the nth picture:

  • iw n - own width
    For each, in the end, you need to find an individual scaling factor s n .
    Adding the proportions w/h of the pictures, we get the proportion of their block when all are of the same height:
    K = k 0 + k 1 + k 2
    • K == W / H of the area where you need to enter the design means that the pictures fit perfectly
      Based on the comparison, we consider the height of the block Hb. It is either equal to W / K when K > W/H; or equal to H.
      Now it remains to calculate the individual coefficients:
      s n = Hb / ih
      You need to multiply the initial dimensions of the picture by this coefficient.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question