Replaced the Stackblur algorithm with RenderScripts native blur for better performance. Only issue yet is, that it seems to cause a memory leak.

This commit is contained in:
Karim Abou Zeid 2015-09-15 18:56:14 +02:00
commit 5f9f2455dc
8 changed files with 121 additions and 450 deletions

View file

@ -22,4 +22,29 @@ public class ImageUtil {
}
return resizedBitmap;
}
public static int calculateInSampleSize(int width, int height, int reqWidth) {
// setting reqWidth matching to desired 1:1 ratio and screen-size
if (width < height) {
reqWidth = (height / width) * reqWidth;
} else {
reqWidth = (width / height) * reqWidth;
}
int inSampleSize = 1;
if (height > reqWidth || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqWidth
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
}