aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2013-09-14 13:49:30 +0200
committerSamuel Tardieu <sam@rfc1149.net>2013-09-14 13:49:30 +0200
commitfa4234853e9f3afb641fb7a0e1fb7b15ef266262 (patch)
tree6822c7ddb07ab25c46d3a35271936be10b5b8c41
parent3e5192d701c76894c38eb82f2c1df31fe4f9fb7e (diff)
downloadcgeo-fa4234853e9f3afb641fb7a0e1fb7b15ef266262.zip
cgeo-fa4234853e9f3afb641fb7a0e1fb7b15ef266262.tar.gz
cgeo-fa4234853e9f3afb641fb7a0e1fb7b15ef266262.tar.bz2
fix #3277: NPE when saving a scaled image
-rw-r--r--main/src/cgeo/geocaching/utils/ImageUtils.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/main/src/cgeo/geocaching/utils/ImageUtils.java b/main/src/cgeo/geocaching/utils/ImageUtils.java
index 6851241..478be1f 100644
--- a/main/src/cgeo/geocaching/utils/ImageUtils.java
+++ b/main/src/cgeo/geocaching/utils/ImageUtils.java
@@ -93,7 +93,7 @@ public final class ImageUtils {
* Image to read
* @param maxXY
* boundings
- * @return String filename and path, NULL if something fails
+ * @return filename and path, <tt>null</tt> if something fails
*/
public static String readScaleAndWriteImage(final String filePath, final int maxXY) {
if (maxXY <= 0) {
@@ -116,12 +116,21 @@ public final class ImageUtils {
return null;
}
final BitmapDrawable scaledImage = scaleBitmapTo(image, maxXY, maxXY);
- final String uploadFilename = ImageUtils.getOutputImageFile().getPath();
+ final File tempImageFile = ImageUtils.getOutputImageFile();
+ if (tempImageFile == null) {
+ Log.e("ImageUtils.readScaleAndWriteImage: unable to write scaled image");
+ return null;
+ }
+ final String uploadFilename = tempImageFile.getPath();
storeBitmap(scaledImage.getBitmap(), Bitmap.CompressFormat.JPEG, 75, uploadFilename);
return uploadFilename;
}
- /** Create a File for saving an image or video */
+ /** Create a File for saving an image or video
+ *
+ * @return the temporary image file to use, or <tt>null</tt> if the media directory could
+ * not be created.
+ * */
public static File getOutputImageFile() {
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.
@@ -133,6 +142,7 @@ public final class ImageUtils {
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!FileUtils.mkdirs(mediaStorageDir)) {
+ Log.e("ImageUtils.getOutputImageFile: cannot create media storage directory");
return null;
}
}