调整图像以适应边框 [英] Resize Image to fit in bounding box

查看:126
本文介绍了调整图像以适应边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是简单的问题,但由于某些原因,我实在不明白这一点今天。

An easy problem, but for some reason I just can't figure this out today.

我需要的图像调整到适合的边框,同时保持高宽比的最大尺寸。

I need to resize an image to the maximum possible size that will fit in a bounding box while maintaining the aspect ratio.

Basicly我找了code填写此功能:

Basicly I'm looking for the code to fill in this function:

void CalcNewDimensions(ref int w, ref int h, int MaxWidth, int MaxHeight);

其中,w&放大器; h为原来的高度和宽度(在)和新的高度和宽度(下)和与了maxWidth了maxHeight定义该图像必须适合的边界框。

Where w & h are the original height and width (in) and the new height and width (out) and MaxWidth and MaxHeight define the bounding box that the image must fit in.

推荐答案

查找这是小:了maxWidth / w或了maxHeight /小时 然后乘以宽和高由数

Find which is smaller: MaxWidth/w or MaxHeight/h Then multiply w and h by that number

说明:

您需要找到缩放因子会使图像的选择。

You need to find the scaling factor which makes the image fit.

要找到缩放因子,S,对于宽度,则s必须是这样的:     S * W =了maxWidth。 因此,在缩放倍率是了maxWidth /瓦特。

To find the scaling factor, s, for the width, then s must be such that: s*w=MaxWidth. Therefore, the scaling factor is MaxWidth/w.

同样的高度。

的一个需要的最缩放(小s)为通过它必须缩放整个图像的因子

The one that requires the most scaling (smaller s) is the factor by which you must scale the whole image.

这篇关于调整图像以适应边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆