@@ -154,7 +154,7 @@ public MediaImageItem(VideoEditor editor, String mediaItemId, String filename, l
154154
155155 final Bitmap imageBitmap ;
156156
157- if (mHeight > maxResolution .second ) {
157+ if (mWidth > maxResolution . first || mHeight > maxResolution .second ) {
158158 /**
159159 * We need to scale the image
160160 */
@@ -971,14 +971,13 @@ private Bitmap scaleImage(String filename, int width, int height)
971971 /**
972972 * Create the bitmap from file
973973 */
974- if (nativeWidth / bitmapWidth > 1 ) {
975-
976- final BitmapFactory .Options options = new BitmapFactory .Options ();
977- options .inSampleSize = nativeWidth / (int )bitmapWidth ;
978- srcBitmap = BitmapFactory .decodeFile (filename , options );
979- } else {
980- srcBitmap = BitmapFactory .decodeFile (filename );
981- }
974+ int sampleSize = (int ) Math .ceil (Math .max (
975+ (float ) nativeWidth / bitmapWidth ,
976+ (float ) nativeHeight / bitmapHeight ));
977+ sampleSize = nextPowerOf2 (sampleSize );
978+ final BitmapFactory .Options options = new BitmapFactory .Options ();
979+ options .inSampleSize = sampleSize ;
980+ srcBitmap = BitmapFactory .decodeFile (filename , options );
982981 } else {
983982 bitmapWidth = width ;
984983 bitmapHeight = height ;
@@ -1009,4 +1008,14 @@ private Bitmap scaleImage(String filename, int width, int height)
10091008 srcBitmap .recycle ();
10101009 return bitmap ;
10111010 }
1011+
1012+ public static int nextPowerOf2 (int n ) {
1013+ n -= 1 ;
1014+ n |= n >>> 16 ;
1015+ n |= n >>> 8 ;
1016+ n |= n >>> 4 ;
1017+ n |= n >>> 2 ;
1018+ n |= n >>> 1 ;
1019+ return n + 1 ;
1020+ }
10121021}
0 commit comments