summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/util/BitmapDecoder.java
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-08-26 21:53:34 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-08-26 21:53:34 +0200
commit616c247d84288c2d5924087a37e05a21ca036c43 (patch)
tree85e59afb3d2a94f9ec64451dcae3e80ed005ac9d /src/de/danoeh/antennapod/util/BitmapDecoder.java
parent40e0950c23e57bfcacce6b84b2b9389005843a8f (diff)
downloadAntennaPod-616c247d84288c2d5924087a37e05a21ca036c43.zip
Cached bitmaps will now have the same size as their ImageViews
Diffstat (limited to 'src/de/danoeh/antennapod/util/BitmapDecoder.java')
-rw-r--r--src/de/danoeh/antennapod/util/BitmapDecoder.java43
1 files changed, 10 insertions, 33 deletions
diff --git a/src/de/danoeh/antennapod/util/BitmapDecoder.java b/src/de/danoeh/antennapod/util/BitmapDecoder.java
index 84cff582f..3d966ee96 100644
--- a/src/de/danoeh/antennapod/util/BitmapDecoder.java
+++ b/src/de/danoeh/antennapod/util/BitmapDecoder.java
@@ -7,26 +7,12 @@ import android.util.Log;
public class BitmapDecoder {
private static final String TAG = "BitmapDecoder";
- private static int calculateSampleSize(int preferredLength, int width,
- int height) {
- int max = Math.max(width, height);
- if (max < preferredLength) {
- return 1;
- } else {
- // find first sample size where max / sampleSize <
- // PREFERRED_LENGTH
- for (int sampleSize = 1, power = 0;; power++, sampleSize = (int) Math
- .pow(2, power)) {
- int newLength = max / sampleSize;
- if (newLength <= preferredLength) {
- if (newLength > 0) {
- return sampleSize;
- } else {
- return sampleSize - 1;
- }
- }
- }
+ private static int calculateSampleSize(int preferredLength, int length) {
+ int sampleSize = 1;
+ if (length > preferredLength) {
+ sampleSize = Math.round(((float) length / (float) preferredLength));
}
+ return sampleSize;
}
public static Bitmap decodeBitmap(int preferredLength, String fileUrl) {
@@ -35,14 +21,13 @@ public class BitmapDecoder {
BitmapFactory.decodeFile(fileUrl, options);
int srcWidth = options.outWidth;
int srcHeight = options.outHeight;
- int sampleSize = calculateSampleSize(preferredLength, srcWidth,
- srcHeight);
-
+ int length = Math.max(srcWidth, srcHeight);
+ int sampleSize = calculateSampleSize(preferredLength, length);
+ Log.d(TAG, "Using samplesize " + sampleSize);
options.inJustDecodeBounds = false;
options.inSampleSize = sampleSize;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- options.inScaled = true;
-
+
Bitmap decodedBitmap = BitmapFactory.decodeFile(fileUrl, options);
if (decodedBitmap == null) {
Log.i(TAG,
@@ -50,14 +35,6 @@ public class BitmapDecoder {
+ fileUrl + ")");
decodedBitmap = BitmapFactory.decodeFile(fileUrl);
}
- if (decodedBitmap != null) {
- return decodedBitmap;
- /*
- return Bitmap.createScaledBitmap(decodedBitmap,
- preferredLength, preferredLength, false);
- */
- } else {
- return null;
- }
+ return decodedBitmap;
}
}