File tree Expand file tree Collapse file tree
lesscode-core/src/main/java/com/jayfeng/lesscode/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .jayfeng .lesscode .core ;
22
3+ import android .graphics .BitmapFactory ;
4+
35public final class BitmapLess {
6+
7+ /**
8+ * 根据reqWidth, reqHeight计算最合适的inSampleSize
9+ * @param options
10+ * @param reqWidth
11+ * @param reqHeight
12+ * @return
13+ */
14+ public static int $inSampleSize (BitmapFactory .Options options , int reqWidth , int reqHeight ) {
15+ // raw height and width of image
16+ int rawWidth = options .outWidth ;
17+ int rawHeight = options .outHeight ;
18+
19+ // calculate best sample size
20+ int inSampleSize = 0 ;
21+ if (rawHeight > reqHeight || rawWidth > reqWidth ) {
22+ float ratioWidth = (float ) rawWidth / reqWidth ;
23+ float ratioHeight = (float ) rawHeight / reqHeight ;
24+ inSampleSize = (int ) Math .min (ratioHeight , ratioWidth );
25+ }
26+ inSampleSize = Math .max (1 , inSampleSize );
27+
28+ return inSampleSize ;
29+ }
430}
You can’t perform that action at this time.
0 commit comments