Volley 图片缩放逻辑
来源:互联网 发布:矩阵分解 als 编辑:程序博客网 时间:2024/05/01 12:58
private static int getResizedDimension(int maxPrimary, int maxSecondary, int actualPrimary, int actualSecondary) { // If no dominant value at all, just return the actual. if (maxPrimary == 0 && maxSecondary == 0) { return actualPrimary; }//如果没有限制,那么就不要缩放了 // If primary is unspecified, scale primary to match secondary's scaling ratio. if (maxPrimary == 0) { double ratio = (double) maxSecondary / (double) actualSecondary; return (int) (actualPrimary * ratio); } if (maxSecondary == 0) { return maxPrimary; }//这个缩放函数要保证原图的宽高比例不变,在这个前提下尽量缩放到宽和要求的近似此时,按比例缩放高如果缩放后的高小于要求的,那么没问题。如果缩放后的高比要求的高要大,那么就反过来让高跟要求的尽量近似,再来调整宽。//图片缩放后要尽量大,因为如果小了拉伸后会使图片失真,如果按上面的方法来则保证宽或高刚好了容器大小一样就不用拉伸了,保证原图的长宽比例不变也是为了保证原图不失真。 double ratio = (double) actualSecondary / (double) actualPrimary; int resized = maxPrimary; if (resized * ratio > maxSecondary) { resized = (int) (maxSecondary / ratio); } return resized; }
static int findBestSampleSize( int actualWidth, int actualHeight, int desiredWidth, int desiredHeight) { double wr = (double) actualWidth / desiredWidth; double hr = (double) actualHeight / desiredHeight; double ratio = Math.min(wr, hr); //我感觉这两个因该是相等的,因为在前一个函数中几种缩放情况的处理中都是保持比例的。这样写是考虑小数上的细微差异吗?按缩放比例小的边来缩放,那么缩放比例大的边缩放过后就会比边界大, 前面一个函数是要一边达到要求在保持原始边的比例的情况下使另一边的长度小于要求跟这一个函数的策略是相反的,这两个函数这样设计难道是一种互补为了使结果尽量的接近要求? float n = 1.0f; while ((n * 2) <= ratio) { n *= 2; }//取到2的幂是因为函数对参数的要求。 return (int) n; }
0 0
- Volley 图片缩放逻辑
- 图片缩放
- 图片缩放
- 图片缩放
- 图片缩放
- 图片缩放
- 缩放图片
- 缩放图片
- 图片缩放
- 图片缩放
- 图片缩放
- 缩放图片
- 缩放图片
- 图片缩放
- 图片缩放
- 图片缩放
- 缩放图片
- 图片缩放
- Kernel启动流程源码解析 9 sched_init
- Spring Boot中Web应用的统一异常处理
- 第十二周 项目3 -图遍历算法实现
- java最基本实现文件上传的过程
- Eclipse启动Tomcat服务器成功,浏览器访问出现404
- Volley 图片缩放逻辑
- new(std::nothrow)
- jar包冲突那些事,编译器不报错,启动报错
- atoi() 函数
- Android实验之实现一个生日备忘簿
- 【iOS沉思录】深思Objective-C中的property属性
- Python缩进问题
- 初步学习opencv的几个程序示例 学习笔记
- leetcode 405. Convert a Number to Hexadecimal