[Android] Prevent crash when image dimensions are incorrect
Geoffrey Métais
git at videolan.org
Tue Dec 18 14:55:51 CET 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec 18 11:41:51 2018 +0100| [bd8629c60961c2a9d0e42030abe2df15cf42e172] | committer: Geoffrey Métais
Prevent crash when image dimensions are incorrect
> https://code.videolan.org/videolan/vlc-android/commit/bd8629c60961c2a9d0e42030abe2df15cf42e172
---
.../src/org/videolan/vlc/gui/helpers/BitmapUtil.java | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.java b/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.java
index ba308ee2e..951c54ccd 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.java
@@ -189,14 +189,17 @@ public class BitmapUtil {
public static Bitmap centerCrop(Bitmap srcBmp, int width, int height) {
final int widthDiff = srcBmp.getWidth()-width;
final int heightDiff = srcBmp.getHeight()-height;
- if (widthDiff <= 0 && heightDiff <= 0)
+ if (widthDiff <= 0 && heightDiff <= 0) return srcBmp;
+ try {
+ return Bitmap.createBitmap(
+ srcBmp,
+ widthDiff/2,
+ heightDiff/2,
+ width,
+ height
+ );
+ } catch (Exception ignored) {
return srcBmp;
- return Bitmap.createBitmap(
- srcBmp,
- widthDiff/2,
- heightDiff/2,
- width,
- height
- );
+ }
}
}
More information about the Android
mailing list