Commit d1fde636 authored by Geoffrey Métais's avatar Geoffrey Métais

Prevent IllegalArgumentException

parent 4c1c4110
...@@ -97,7 +97,7 @@ public class BitmapUtil { ...@@ -97,7 +97,7 @@ public class BitmapUtil {
} }
} }
public static Bitmap fetchPicture(MediaWrapper media) { private static Bitmap fetchPicture(MediaWrapper media) {
final BitmapCache cache = BitmapCache.getInstance(); final BitmapCache cache = BitmapCache.getInstance();
Bitmap picture = readCoverBitmap(media.getArtworkURL()); Bitmap picture = readCoverBitmap(media.getArtworkURL());
...@@ -175,32 +175,28 @@ public class BitmapUtil { ...@@ -175,32 +175,28 @@ public class BitmapUtil {
/** /**
* A helper function to return the byte usage per pixel of a bitmap based on its configuration. * A helper function to return the byte usage per pixel of a bitmap based on its configuration.
*/ */
static int getBytesPerPixel(Bitmap.Config config) { private static int getBytesPerPixel(Bitmap.Config config) {
if (config == Bitmap.Config.ARGB_8888) { if (config == Bitmap.Config.ARGB_8888)
return 4; return 4;
} else if (config == Bitmap.Config.RGB_565) { else if (config == Bitmap.Config.RGB_565)
return 2; return 2;
} else if (config == Bitmap.Config.ARGB_4444) { else if (config == Bitmap.Config.ARGB_4444)
return 2; return 2;
} else if (config == Bitmap.Config.ALPHA_8) { else
return 1; return 1;
}
return 1;
} }
public static Bitmap centerCrop(Bitmap srcBmp, int width, int height) { public static Bitmap centerCrop(Bitmap srcBmp, int width, int height) {
Bitmap dstBmp; final int widthDiff = srcBmp.getWidth()-width;
int widthDiff = srcBmp.getWidth()-width; final int heightDiff = srcBmp.getHeight()-height;
int heightDiff = srcBmp.getHeight()-height; if (widthDiff <= 0 && heightDiff <= 0)
if (widthDiff == 0 && heightDiff == 0)
return srcBmp; return srcBmp;
dstBmp = Bitmap.createBitmap( return Bitmap.createBitmap(
srcBmp, srcBmp,
widthDiff/2, widthDiff/2,
heightDiff/2, heightDiff/2,
width, width,
height height
); );
return dstBmp;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment