Commit 106ef3d4 authored by Sébastien Toque's avatar Sébastien Toque
Browse files

improve border detection in thumbnails

parent 4e4fd68a
...@@ -102,9 +102,11 @@ public class Util { ...@@ -102,9 +102,11 @@ public class Util {
public static Bitmap cropBorders(Bitmap bitmap, int width, int height) public static Bitmap cropBorders(Bitmap bitmap, int width, int height)
{ {
int top = 0; int top = 0;
for (int i = 0; i < height; i++) { for (int i = 0; i < height / 2; i++) {
int pixel = bitmap.getPixel(width / 2, i); int pixel1 = bitmap.getPixel(width / 2, i);
if (pixel == 0 || pixel == -16777216) { int pixel2 = bitmap.getPixel(width / 2, height - i - 1);
if ((pixel1 == 0 || pixel1 == -16777216) &&
(pixel2 == 0 || pixel2 == -16777216)) {
top = i; top = i;
} else { } else {
break; break;
...@@ -112,15 +114,20 @@ public class Util { ...@@ -112,15 +114,20 @@ public class Util {
} }
int left = 0; int left = 0;
for (int i = 0; i < width; i++) { for (int i = 0; i < width / 2; i++) {
int pixel = bitmap.getPixel(i, height / 2); int pixel1 = bitmap.getPixel(i, height / 2);
if (pixel == 0 || pixel == -16777216) { int pixel2 = bitmap.getPixel(width - i - 1, height / 2);
if ((pixel1 == 0 || pixel1 == -16777216) &&
(pixel2 == 0 || pixel2 == -16777216)) {
left = i; left = i;
} else { } else {
break; break;
} }
} }
if (left >= width / 2 - 10 || top >= height / 2 - 10)
return bitmap;
// Cut off the transparency on the borders // Cut off the transparency on the borders
return Bitmap.createBitmap(bitmap, left, top, return Bitmap.createBitmap(bitmap, left, top,
(width - (2 * left)), (height - (2 * top))); (width - (2 * left)), (height - (2 * top)));
......
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