[ 
https://issues.apache.org/jira/browse/CB-1700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13543600#comment-13543600
 ] 

Darryl Champagne commented on CB-1700:
--------------------------------------

If I remember correctly, after testing, the Camera code ended up being OK.
The following patch is what I used (based off 2.2.0, if I remember correctly.  
It fixes two instances of this issue, an issue where it failed to read images 
from the external SD Card that were referenced via content:, and checks for a 
null before attempting to scale an invalid image (to prevent a crash when 
reading a corrupted image file).  Obviously the extra logging is not necessary.

I have not reviewed the changes since then, so of course, there may be some 
differences...

diff --git a/framework/src/org/apache/cordova/CameraLauncher.java 
b/framework/src/org/apache/cordova/CameraLauncher.java
index f9cfb94..de3b316 100755
--- a/framework/src/org/apache/cordova/CameraLauncher.java
+++ b/framework/src/org/apache/cordova/CameraLauncher.java
@@ -382,7 +382,7 @@ public class CameraLauncher extends CordovaPlugin 
implements MediaScannerConnect
                         this.callbackContext.success(uri.toString());
                     } else {
                         // Get the path to the image. Makes loading so much 
easier.
-                        String imagePath = FileUtils.getRealPathFromURI(uri, 
this.cordova);
+                        String imagePath = 
FileUtils.stripFileProtocol(FileUtils.getRealPathFromURI(uri, this.cordova));
                         String mimeType = FileUtils.getMimeType(imagePath);
                         // Log.d(LOG_TAG, "Real path = " + imagePath);
                         // Log.d(LOG_TAG, "mime type = " + mimeType);
@@ -431,7 +431,7 @@ public class CameraLauncher extends CordovaPlugin 
implements MediaScannerConnect
                                     ExifHelper exif = new ExifHelper();
                                     try {
                                         if (this.encodingType == JPEG) {
-                                            exif.createInFile(resizePath);
+                                            exif.createInFile(imagePath);
                                             exif.readExifData();
                                             rotate = exif.getOrientation();
                                         }
@@ -445,7 +445,7 @@ public class CameraLauncher extends CordovaPlugin 
implements MediaScannerConnect
 
                                     // Restore exif data to file
                                     if (this.encodingType == JPEG) {
-                                        
exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.cordova));
+                                        exif.createOutFile(resizePath);
                                         exif.writeExifData();
                                     }
 
@@ -567,6 +567,11 @@ public class CameraLauncher extends CordovaPlugin 
implements MediaScannerConnect
         options.inJustDecodeBounds = false;
         options.inSampleSize = calculateSampleSize(options.outWidth, 
options.outHeight, this.targetWidth, this.targetHeight);
         Bitmap unscaledBitmap = BitmapFactory.decodeFile(imagePath, options);
+        Log.d(LOG_TAG,"About to return scaled Bitmap");
+        if (unscaledBitmap == null) {
+            Log.e(LOG_TAG,"Failed to load bitmap");
+            return null;
+        }
 
         return Bitmap.createScaledBitmap(unscaledBitmap, widthHeight[0], 
widthHeight[1], true);
     }

                
> Exif data corrupted on Android loading photos from Gallery
> ----------------------------------------------------------
>
>                 Key: CB-1700
>                 URL: https://issues.apache.org/jira/browse/CB-1700
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 2.1.0, 2.2.0
>         Environment: Samsung Galaxy SII
>            Reporter: Darryl Champagne
>            Assignee: Simon MacDonald
>
> Source and Target filenames are reversed in CameraLauncher.java when 
> returning a picture from the gallery that requires resizing. 
> Exif data is being read in from the resized image (around line 433, in 
> onActivityResult):
>     if (this.encodingType == JPEG) {
>         exif.createInFile(resizePath);
>         exif.readExifData();
>         rotate = exif.getOrientation();
>     }
> And being written back to the original file, rather than the resized file 
> that is actually returned (around line 446):
>     // Restore exif data to file
>     if (this.encodingType == JPEG) {
>         exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.cordova));
>         exif.writeExifData();
>     }
> ...
>     this.callbackContext.success("file://" + resizePath + "?" + 
> System.currentTimeMillis());
> This means that the almost nonexistent EXIF data in the output file gets 
> written to the original file (usually doing nothing), and the valid data is 
> not returned in the resized file.  The inFile should be imagePath (or 
> recreated), and the outfile should be resizePath.
> The sending filename back from the Camera appears to have a similar issue.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to