summaryrefslogtreecommitdiffstats
path: root/gallerycommon
diff options
context:
space:
mode:
authorWei Huang <weih@google.com>2011-09-02 11:40:00 -0700
committerWei Huang <weih@google.com>2011-09-02 11:40:00 -0700
commit9c12d7512df688131384328fb6ffb89b36cc4393 (patch)
tree6fec2f9ec659b03147d952bfe9a4a3321342e873 /gallerycommon
parent28eb58218cfd50d07e8e333b4b7fd000037c6749 (diff)
downloadandroid_packages_apps_Snap-9c12d7512df688131384328fb6ffb89b36cc4393.tar.gz
android_packages_apps_Snap-9c12d7512df688131384328fb6ffb89b36cc4393.tar.bz2
android_packages_apps_Snap-9c12d7512df688131384328fb6ffb89b36cc4393.zip
bug #5252975: guard against null bitmap object, don't NPE.
- check for null Bitmap object before using. Change-Id: I99d85916dae45128d67be084860d66dd89ec2f95
Diffstat (limited to 'gallerycommon')
-rw-r--r--gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java b/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java
index df9b93fbd..29f86e056 100644
--- a/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java
+++ b/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java
@@ -114,6 +114,8 @@ public class BitmapUtils {
public static Bitmap resizeDownToPixels(
Bitmap bitmap, int targetPixels, boolean recycle) {
+ if (bitmap == null) return null;
+
int width = bitmap.getWidth();
int height = bitmap.getHeight();
float scale = (float) Math.sqrt(
@@ -138,7 +140,7 @@ public class BitmapUtils {
}
private static Bitmap.Config getConfig(Bitmap bitmap) {
- Bitmap.Config config = bitmap.getConfig();
+ Bitmap.Config config = (bitmap != null ? bitmap.getConfig() : null);
if (config == null) {
config = Bitmap.Config.ARGB_8888;
}
@@ -147,6 +149,8 @@ public class BitmapUtils {
public static Bitmap resizeDownBySideLength(
Bitmap bitmap, int maxLength, boolean recycle) {
+ if (bitmap == null) return null;
+
int srcWidth = bitmap.getWidth();
int srcHeight = bitmap.getHeight();
float scale = Math.min(
@@ -157,6 +161,8 @@ public class BitmapUtils {
// Crops a square from the center of the original image.
public static Bitmap cropCenter(Bitmap bitmap, boolean recycle) {
+ if (bitmap == null) return null;
+
int width = bitmap.getWidth();
int height = bitmap.getHeight();
if (width == height) return bitmap;
@@ -173,6 +179,8 @@ public class BitmapUtils {
public static Bitmap resizeDownAndCropCenter(Bitmap bitmap, int size,
boolean recycle) {
+ if (bitmap == null) return null;
+
int w = bitmap.getWidth();
int h = bitmap.getHeight();
int minSide = Math.min(w, h);
@@ -203,6 +211,8 @@ public class BitmapUtils {
}
public static Bitmap rotateBitmap(Bitmap source, int rotation, boolean recycle) {
+ if (source == null) return null;
+
int w = source.getWidth();
int h = source.getHeight();
Matrix m = new Matrix();
@@ -261,6 +271,8 @@ public class BitmapUtils {
}
public static byte[] compressBitmap(Bitmap bitmap) {
+ if (bitmap == null) return null;
+
ByteArrayOutputStream os = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG,
COMPRESS_JPEG_QUALITY, os);
@@ -281,6 +293,8 @@ public class BitmapUtils {
}
public static byte[] compressToBytes(Bitmap bitmap, int quality) {
+ if (bitmap == null) return null;
+
ByteArrayOutputStream baos = new ByteArrayOutputStream(65536);
bitmap.compress(CompressFormat.JPEG, quality, baos);
return baos.toByteArray();