@@ -741,6 +741,23 @@ private void processResultFromGallery(int destType, Intent intent) {
741
741
742
742
String uriString = uri .toString ();
743
743
String mimeTypeOfGalleryFile = FileHelper .getMimeType (uriString , this .cordova );
744
+
745
+ // If you ask for video or the selected file cannot be processed
746
+ // there will be no attempt to resize any returned data.
747
+ if (this .mediaType == VIDEO || !isImageMimeTypeProcessable (mimeTypeOfGalleryFile )) {
748
+ this .callbackContext .success (uriString );
749
+ return ;
750
+ }
751
+
752
+ // This is a special case to just return the path as no scaling,
753
+ // rotating, nor compressing needs to be done
754
+ if (this .targetHeight == -1 && this .targetWidth == -1 &&
755
+ destType == FILE_URI && !this .correctOrientation &&
756
+ getMimetypeForEncodingType ().equalsIgnoreCase (mimeTypeOfGalleryFile )) {
757
+ this .callbackContext .success (uriString );
758
+ return ;
759
+ }
760
+
744
761
InputStream input ;
745
762
try {
746
763
input = cordova .getActivity ().getContentResolver ().openInputStream (uri );
@@ -756,105 +773,53 @@ private void processResultFromGallery(int destType, Intent intent) {
756
773
757
774
try {
758
775
byte [] data = readData (input );
776
+ Bitmap bitmap = null ;
759
777
760
- // If you ask for video or the selected file cannot be processed
761
- // there will be no attempt to resize any returned data.
762
- if (this .mediaType == VIDEO || !isImageMimeTypeProcessable (mimeTypeOfGalleryFile )) {
763
- this .callbackContext .success (uriString );
764
- } else {
765
- Bitmap bitmap = null ;
778
+ try {
779
+ bitmap = getScaledAndRotatedBitmap (data , mimeTypeOfGalleryFile );
780
+ } catch (IOException e ) {
781
+ e .printStackTrace ();
782
+ }
766
783
767
- // This is a special case to just return the path as no scaling,
768
- // rotating, nor compressing needs to be done
769
- if (this .targetHeight == -1 && this .targetWidth == -1 &&
770
- destType == FILE_URI && !this .correctOrientation &&
771
- getMimetypeForEncodingType ().equalsIgnoreCase (mimeTypeOfGalleryFile )) {
772
- this .callbackContext .success (uriString );
773
- } else {
774
- try {
775
- bitmap = getScaledAndRotatedBitmap (data , mimeTypeOfGalleryFile );
776
- } catch (IOException e ) {
777
- e .printStackTrace ();
778
- }
779
- if (bitmap == null ) {
780
- LOG .d (LOG_TAG , "I either have an unreadable uri or null bitmap" );
781
- this .failPicture ("Unable to create bitmap!" );
782
- return ;
783
- }
784
+ if (bitmap == null ) {
785
+ LOG .d (LOG_TAG , "I either have an unreadable uri or null bitmap" );
786
+ this .failPicture ("Unable to create bitmap!" );
787
+ return ;
788
+ }
784
789
785
- // If sending base64 image back
786
- if (destType == DATA_URL ) {
787
- this .processPicture (bitmap , this .encodingType );
788
- }
790
+ // If sending base64 image back
791
+ if (destType == DATA_URL ) {
792
+ this .processPicture (bitmap , this .encodingType );
793
+ }
794
+ // If sending filename back
795
+ else if (destType == FILE_URI ) {
796
+ // Did we modify the image?
797
+ if ((this .targetHeight > 0 && this .targetWidth > 0 ) ||
798
+ (this .correctOrientation && this .orientationCorrected ) ||
799
+ !mimeTypeOfGalleryFile .equalsIgnoreCase (getMimetypeForEncodingType ())) {
800
+ try {
801
+ String modifiedPath = this .outputModifiedBitmap (bitmap , uri , mimeTypeOfGalleryFile );
802
+ // The modified image is cached by the app in order to get around this and not have to delete you
803
+ // application cache I'm adding the current system time to the end of the file url.
804
+ this .callbackContext .success ("file://" + modifiedPath + "?" + System .currentTimeMillis ());
789
805
790
- // If sending filename back
791
- else if (destType == FILE_URI ) {
792
- // Did we modify the image?
793
- if ((this .targetHeight > 0 && this .targetWidth > 0 ) ||
794
- (this .correctOrientation && this .orientationCorrected ) ||
795
- !mimeTypeOfGalleryFile .equalsIgnoreCase (getMimetypeForEncodingType ())) {
796
- try {
797
- String modifiedPath = this .outputModifiedBitmap (bitmap , uri , mimeTypeOfGalleryFile );
798
- // The modified image is cached by the app in order to get around this and not have to delete you
799
- // application cache I'm adding the current system time to the end of the file url.
800
- this .callbackContext .success ("file://" + modifiedPath + "?" + System .currentTimeMillis ());
801
-
802
- } catch (Exception e ) {
803
- e .printStackTrace ();
804
- this .failPicture ("Error retrieving image: " + e .getLocalizedMessage ());
805
- }
806
- } else {
807
- this .callbackContext .success (uriString );
808
- }
809
- }
810
- if (bitmap != null ) {
811
- bitmap .recycle ();
812
- bitmap = null ;
806
+ } catch (Exception e ) {
807
+ e .printStackTrace ();
808
+ this .failPicture ("Error retrieving image: " + e .getLocalizedMessage ());
813
809
}
814
- System .gc ();
815
- }
816
- if (bitmap == null ) {
817
- LOG .d (LOG_TAG , "I either have an unreadable uri or null bitmap" );
818
- this .failPicture ("Unable to create bitmap!" );
819
- return ;
820
- }
821
-
822
- // If sending base64 image back
823
- if (destType == DATA_URL ) {
824
- this .processPicture (bitmap , this .encodingType );
810
+ } else {
811
+ this .callbackContext .success (uriString );
825
812
}
813
+ }
826
814
827
- // If sending filename back
828
- else if (destType == FILE_URI ) {
829
- // Did we modify the image?
830
- if ( (this .targetHeight > 0 && this .targetWidth > 0 ) ||
831
- (this .correctOrientation && this .orientationCorrected ) ||
832
- !mimeTypeOfGalleryFile .equalsIgnoreCase (getMimetypeForEncodingType ()))
833
- {
834
- try {
835
- String modifiedPath = this .outputModifiedBitmap (bitmap , uri , mimeTypeOfGalleryFile );
836
- // The modified image is cached by the app in order to get around this and not have to delete you
837
- // application cache I'm adding the current system time to the end of the file url.
838
- this .callbackContext .success ("file://" + modifiedPath + "?" + System .currentTimeMillis ());
839
-
840
- } catch (Exception e ) {
841
- e .printStackTrace ();
842
- this .failPicture ("Error retrieving image: " +e .getLocalizedMessage ());
843
- }
844
- } else {
845
- this .callbackContext .success (uriString );
846
- }
847
- }
848
- if (bitmap != null ) {
849
- bitmap .recycle ();
850
- bitmap = null ;
851
- }
852
- System .gc ();
815
+ if (bitmap != null ) {
816
+ bitmap .recycle ();
817
+ bitmap = null ;
853
818
}
854
819
820
+ System .gc ();
855
821
input .close ();
856
- }
857
- catch (Exception e ) {
822
+ } catch (Exception e ) {
858
823
try {
859
824
input .close ();
860
825
} catch (IOException ex ) {
0 commit comments