Bitmapfun Sample: Minor updates to match zip file in training class.
Change-Id: I0fa13d5d8947532e9b5906b863ca75e5c85ac544
This commit is contained in:
@@ -506,20 +506,23 @@ public class ImageCache {
|
||||
private static boolean canUseForInBitmap(
|
||||
Bitmap candidate, BitmapFactory.Options targetOptions) {
|
||||
|
||||
if (Utils.hasKitKat()) {
|
||||
int width = targetOptions.outWidth / targetOptions.inSampleSize;
|
||||
int height = targetOptions.outHeight / targetOptions.inSampleSize;
|
||||
int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
|
||||
return byteCount <= candidate.getAllocationByteCount();
|
||||
if (!Utils.hasKitKat()) {
|
||||
// On earlier versions, the dimensions must match exactly and the inSampleSize must be 1
|
||||
return candidate.getWidth() == targetOptions.outWidth
|
||||
&& candidate.getHeight() == targetOptions.outHeight
|
||||
&& targetOptions.inSampleSize == 1;
|
||||
}
|
||||
|
||||
return candidate.getWidth() == targetOptions.outWidth
|
||||
&& candidate.getHeight() == targetOptions.outHeight
|
||||
&& targetOptions.inSampleSize <= 1;
|
||||
// From Android 4.4 (KitKat) onward we can re-use if the byte size of the new bitmap
|
||||
// is smaller than the reusable bitmap candidate allocation byte count.
|
||||
int width = targetOptions.outWidth / targetOptions.inSampleSize;
|
||||
int height = targetOptions.outHeight / targetOptions.inSampleSize;
|
||||
int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
|
||||
return byteCount <= candidate.getAllocationByteCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the byte usage per pixel of a bitmap based on it's configuration.
|
||||
* Return the byte usage per pixel of a bitmap based on its configuration.
|
||||
* @param config The bitmap configuration.
|
||||
* @return The byte usage per pixel.
|
||||
*/
|
||||
@@ -528,6 +531,8 @@ public class ImageCache {
|
||||
return 4;
|
||||
} else if (config == Config.RGB_565) {
|
||||
return 2;
|
||||
} else if (config == Config.ARGB_4444) {
|
||||
return 2;
|
||||
} else if (config == Config.ALPHA_8) {
|
||||
return 1;
|
||||
}
|
||||
@@ -582,7 +587,10 @@ public class ImageCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size in bytes of a bitmap in a BitmapDrawable.
|
||||
* Get the size in bytes of a bitmap in a BitmapDrawable. Note that from Android 4.4 (KitKat)
|
||||
* onward this returns the allocated memory size of the bitmap which can be larger than the
|
||||
* actual bitmap data byte count (in the case it was re-used).
|
||||
*
|
||||
* @param value
|
||||
* @return size in bytes
|
||||
*/
|
||||
|
||||
@@ -207,12 +207,7 @@ public class ImageResizer extends ImageWorker {
|
||||
Bitmap inBitmap = cache.getBitmapFromReusableSet(options);
|
||||
|
||||
if (inBitmap != null) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.d(TAG, "Found bitmap to use for inBitmap");
|
||||
}
|
||||
options.inBitmap = inBitmap;
|
||||
} else {
|
||||
Log.d(TAG, "Did NOT find bitmap to use for inBitmap");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user