栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

调整图像大小并保持宽高比以适合iPhone的算法

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

调整图像大小并保持宽高比以适合iPhone的算法

我认为以下内容应该可以给您这个想法。它不是任何特定的语言,而是类似C的伪代码。

shortSideMax = 640;longSideMax = 960;function Resize(image){    if (image.width >= image.height)    {        if (image.width <= longSideMax && image.height <= shortSideMax) return image;  // no resizing required        wRatio = longSideMax / image.width;        hRatio = shortSideMax / image.height;    }    else    {        if (image.height <= longSideMax && image.width <= shortSideMax) return image; // no resizing required        wRatio = shortSideMax / image.width;        hRatio = longSideMax / image.height;    }    // hRatio and wRatio now have the scaling factors for height and width.    // You want the smallest of the two to ensure that the resulting image    // fits in the desired frame and maintains the aspect ratio.    resizeRatio = Min(wRatio, hRatio);    newHeight = image.Height * resizeRatio;    newWidth = image.Width * resizeRatio;    // Now call function to resize original image to [newWidth, newHeight]    // and return the result.}

这段代码的效率或您拥有的代码都不会成为问题。实际调整图像大小所需的时间将使进行两次比较,两次除法和两次乘法所需的时间相形见war。

这是“更数学”的方法吗?我想是因为它会将您的四个案例分解为两个。但是方法本质上是相同的。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/637529.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号