保持宽高比缩放的算法
来源:互联网 发布:算法中log2是什么意思 编辑:程序博客网 时间:2024/06/09 23:50
偶尔看到网上一些实现的乱糟糟的算法,于心不忍,贴出来这个函数,以后大家都不用费劲了:
static protected float getRatio(Rect boundRect , int target_width,int target_height)
{float xRatio = (float) 1.0;
float yRatio = (float) 1.0;
float fRatio = (float) 1.0;
//sign bound larger than standard size.
xRatio = target_width / (float)boundRect.width();
yRatio = target_height/ (float)(boundRect.height() * xRatio);
if(xRatio < (float)1.0)//x larger ,and use xRatio
{
if(yRatio < 1.0)//and y still larger
{
fRatio = (target_height)/ (float)boundRect.height();
}else
fRatio = xRatio;
}else
{
fRatio = (target_height)/ (float)boundRect.height();
}
if(fRatio > 1.0) // if boundRect smaller than target area ,keep size of it ,not zoom in.
fRatio = (float) 1.0;
return fRatio;
}
0 0
- 保持宽高比缩放的算法
- 保持宽高比的自定义View
- Android 代码中动态添加图片使图片缩放并保持宽高比
- 关于Qt窗口保持宽高比的研究
- android的ImageView 充满控件,并且保持宽高比
- Imageview保持宽高比FILL_PARENT
- 图片保持固定宽高比
- Android图片保持宽高比技巧
- 保持view宽高比,实现屏幕自适应
- CSS实现自适应下保持宽高比
- 保留图片的宽高比,实现宽高等比例缩放
- android将给定图片维持宽高比缩放后,截取正中间的正方形部分
- android将给定图片维持宽高比缩放后,截取正中间的正方形部分
- 可以设置宽高比,宽度确定,高度比例缩放的ImageView快速实现
- 计算BitmapFactory.Options.inSampleSize的缩放比算法工具
- CSS保持长宽比
- 网页的宽高时时随浏览器缩放而缩放
- 高响应比调度算法
- 遇见C++ AMP:GPU的线程模型和内存模型
- int、bigint、smallint 和 tinyint (Transact-SQL)
- 小波变换和motion信号处理(三)
- Delphi TStream,TMemoryStream,TFileStream等 详细介绍
- Presto:Facebook的分布式SQL查询引擎
- 保持宽高比缩放的算法
- 一切为了SVM
- VC++编译错误解决方法
- S3C2440上LCD驱动(FrameBuffer)实例开发讲解(一)
- vSphere HA状况:未知配置错误解决办法
- 深入理解C语言
- vector stable_sort结合排序规则将牌按照大小和长短进行排序, 为了三带二的牌型等
- linux/android 调试专用工具
- S3C2440上LCD驱动(FrameBuffer)实例开发讲解(二)