Кнопка «Нравится» ListView внутри ячейки

Вы хотите сохранить соотношение сторон исходного изображения. Это соотношение между шириной и высотой изображения. Таким образом, вы вычисляете коэффициент, с помощью которого вы должны изменить размер изображения в вертикальном и горизонтальном направлениях, а затем вы держите верхнюю из двух. В псевдокоде:

target_height = 768
target_width = 1024
# v_fact and h_fact are the factor by which the original vertical / horizontal
# image sizes should be multiplied to get the image to your target size.
v_fact = target_height / im_height 
h_fact = target_width / im_width
# you want to resize the image by the same factor in both vertical 
# and horizontal direction, so you need to pick the correct factor from
# v_fact / h_fact so that the largest (relative to target) of the new height/width
# equals the target height/width and the smallest is lower than the target.
# this is the lowest of the two factors
im_fact = min(v_fact, h_fact)
new_height = im_height * im_fact
new_width = im_width * im_fact
image.resize(new_width, new_height)
0
задан Jose 30 December 2018 в 20:55
поделиться