@@ -24,10 +24,10 @@ public class ETImage {
2424 private final Uri uri ;
2525 private final ContentResolver contentResolver ;
2626
27- ETImage (ContentResolver contentResolver , Uri uri ) {
27+ ETImage (ContentResolver contentResolver , Uri uri , int sideSize ) {
2828 this .contentResolver = contentResolver ;
2929 this .uri = uri ;
30- bytes = getBytesFromImageURI (uri );
30+ bytes = getBytesFromImageURI (uri , sideSize );
3131 }
3232
3333 public int getWidth () {
@@ -64,10 +64,9 @@ public float[] getFloats() {
6464 return floatArray ;
6565 }
6666
67- private byte [] getBytesFromImageURI (Uri uri ) {
67+ private byte [] getBytesFromImageURI (Uri uri , int sideSize ) {
6868 try {
69- int RESIZED_IMAGE_WIDTH = 336 ;
70- Bitmap bitmap = resizeImage (uri , RESIZED_IMAGE_WIDTH );
69+ Bitmap bitmap = resizeImage (uri , sideSize );
7170
7271 if (bitmap == null ) {
7372 ETLogging .getInstance ().log ("Unable to get bytes from Image URI. Bitmap is null" );
@@ -102,7 +101,7 @@ private byte[] getBytesFromImageURI(Uri uri) {
102101 }
103102
104103 @ Nullable
105- private Bitmap resizeImage (Uri uri , int maxLength ) throws FileNotFoundException {
104+ private Bitmap resizeImage (Uri uri , int sideSize ) throws FileNotFoundException {
106105 InputStream inputStream = contentResolver .openInputStream (uri );
107106 if (inputStream == null ) {
108107 ETLogging .getInstance ().log ("Unable to resize image, input streams is null" );
@@ -114,21 +113,6 @@ private Bitmap resizeImage(Uri uri, int maxLength) throws FileNotFoundException
114113 return null ;
115114 }
116115
117- float aspectRatio ;
118- int finalWidth , finalHeight ;
119-
120- if (bitmap .getWidth () > bitmap .getHeight ()) {
121- // width > height --> width = maxLength, height scale with aspect ratio
122- aspectRatio = bitmap .getWidth () / (float ) bitmap .getHeight ();
123- finalWidth = maxLength ;
124- finalHeight = Math .round (maxLength / aspectRatio );
125- } else {
126- // height >= width --> height = maxLength, width scale with aspect ratio
127- aspectRatio = bitmap .getHeight () / (float ) bitmap .getWidth ();
128- finalHeight = maxLength ;
129- finalWidth = Math .round (maxLength / aspectRatio );
130- }
131-
132- return Bitmap .createScaledBitmap (bitmap , finalWidth , finalHeight , false );
116+ return Bitmap .createScaledBitmap (bitmap , sideSize , sideSize , false );
133117 }
134118}
0 commit comments