[Android] Move centerCrop method in BitmapUtil

Geoffrey Métais git at videolan.org
Thu Jun 15 14:59:45 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jun 15 14:55:44 2017 +0200| [c2609d0c631a98395d888363f69acd09427720f9] | committer: Geoffrey Métais

Move centerCrop method in BitmapUtil

> https://code.videolan.org/videolan/vlc-android/commit/c2609d0c631a98395d888363f69acd09427720f9
---

 .../org/videolan/vlc/gui/helpers/BitmapUtil.java   | 16 +++++++++++++
 .../org/videolan/vlc/util/ThumbnailsProvider.java  | 27 +++++-----------------
 2 files changed, 22 insertions(+), 21 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 af85862b7..4b8009710 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.java
@@ -187,4 +187,20 @@ public class BitmapUtil {
         }
         return 1;
     }
+
+    public static Bitmap centerCrop(Bitmap srcBmp, int width, int height) {
+        Bitmap dstBmp;
+        int widthDiff = srcBmp.getWidth()-width;
+        int heightDiff = srcBmp.getHeight()-height;
+        if (widthDiff == 0 && heightDiff == 0)
+            return srcBmp;
+        dstBmp = Bitmap.createBitmap(
+                srcBmp,
+                widthDiff/2,
+                heightDiff/2,
+                width,
+                height
+        );
+        return dstBmp;
+    }
 }
diff --git a/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java b/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
index 88c86b1be..486936da5 100644
--- a/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
+++ b/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
@@ -13,6 +13,7 @@ import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.helpers.AudioUtil;
 import org.videolan.vlc.gui.helpers.BitmapCache;
+import org.videolan.vlc.gui.helpers.BitmapUtil;
 import org.videolan.vlc.media.MediaGroup;
 
 import java.io.ByteArrayOutputStream;
@@ -102,21 +103,21 @@ public class ThumbnailsProvider {
         switch (count) {
             case 2:
                 for (int i = 0; i < count; ++i)
-                    sourcesImages[i] = centerCrop(sourcesImages[i], minWidth/2, minHeight);
+                    sourcesImages[i] = BitmapUtil.centerCrop(sourcesImages[i], minWidth/2, minHeight);
                 canvas.drawBitmap(sourcesImages[0], 0, 0, null);
                 canvas.drawBitmap(sourcesImages[1], minWidth / 2, 0, null);
                 break;
             case 3:
-                sourcesImages[0] = centerCrop(sourcesImages[0], minWidth/2, minHeight/2);
-                sourcesImages[1] = centerCrop(sourcesImages[1], minWidth/2, minHeight/2);
-                sourcesImages[2] = centerCrop(sourcesImages[2], minWidth, minHeight/2);
+                sourcesImages[0] = BitmapUtil.centerCrop(sourcesImages[0], minWidth/2, minHeight/2);
+                sourcesImages[1] = BitmapUtil.centerCrop(sourcesImages[1], minWidth/2, minHeight/2);
+                sourcesImages[2] = BitmapUtil.centerCrop(sourcesImages[2], minWidth, minHeight/2);
                 canvas.drawBitmap(sourcesImages[0], 0, 0, null);
                 canvas.drawBitmap(sourcesImages[1], minWidth / 2, 0, null);
                 canvas.drawBitmap(sourcesImages[2], 0, minHeight/2, null);
                 break;
             case 4:
                 for (int i = 0; i < count; ++i)
-                    sourcesImages[i] = centerCrop(sourcesImages[i], minWidth, minHeight);
+                    sourcesImages[i] = BitmapUtil.centerCrop(sourcesImages[i], minWidth, minHeight);
                 canvas.drawBitmap(sourcesImages[0], 0, 0, null);
                 canvas.drawBitmap(sourcesImages[1], minWidth , 0, null);
                 canvas.drawBitmap(sourcesImages[2], 0, minHeight, null);
@@ -126,22 +127,6 @@ public class ThumbnailsProvider {
         return bmOverlay;
     }
 
-    private static Bitmap centerCrop(Bitmap srcBmp, int width, int height) {
-        Bitmap dstBmp;
-        int widthDiff = srcBmp.getWidth()-width;
-        int heightDiff = srcBmp.getHeight()-height;
-        if (widthDiff == 0 && heightDiff == 0)
-            return srcBmp;
-        dstBmp = Bitmap.createBitmap(
-                srcBmp,
-                widthDiff/2,
-                heightDiff/2,
-                width,
-                height
-        );
-        return dstBmp;
-    }
-
     private static void saveOnDisk(Bitmap bitmap, String destPath) {
         ByteArrayOutputStream stream = new ByteArrayOutputStream();
         bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);



More information about the Android mailing list