@@ -614,6 +614,17 @@ private Bitmap getImage(BitmapFactory.Options opts)
614
614
return image ;
615
615
}
616
616
617
+ private int getImageOrientation ()
618
+ {
619
+ int rotation = 0 ;
620
+ try (InputStream stream = getInputStream ()) {
621
+ rotation = TiImageHelper .getOrientation (stream );
622
+ } catch (Exception ex ) {
623
+ Log .e (TAG , "Failed to fetch image EXIF orientation from blob." , ex );
624
+ }
625
+ return rotation ;
626
+ }
627
+
617
628
@ Kroll .method
618
629
public TiBlob imageAsCropped (Object params )
619
630
{
@@ -626,10 +637,7 @@ public TiBlob imageAsCropped(Object params)
626
637
return null ;
627
638
}
628
639
629
- int rotation = 0 ;
630
- if (type == TYPE_FILE ) {
631
- rotation = TiImageHelper .getOrientation (getNativePath ());
632
- }
640
+ int rotation = getImageOrientation ();
633
641
634
642
KrollDict options = new KrollDict ((HashMap ) params );
635
643
int widthCropped = options .optInt (TiC .PROPERTY_WIDTH , width );
@@ -718,13 +726,10 @@ public TiBlob imageAsResized(Number width, Number height)
718
726
opts .inPreferredConfig = Bitmap .Config .ARGB_8888 ;
719
727
}
720
728
721
- String nativePath = getNativePath ();
722
- int rotation = 0 ;
723
- if (type == TYPE_FILE ) {
724
- rotation = TiImageHelper .getOrientation (nativePath );
725
- }
729
+ int rotation = getImageOrientation ();
726
730
727
731
String key = null ;
732
+ String nativePath = getNativePath ();
728
733
if (nativePath != null ) {
729
734
key = nativePath + "_imageAsResized_" + rotation + "_" + dstWidth + "_" + dstHeight ;
730
735
Bitmap bitmap = mMemoryCache .get (key );
@@ -747,6 +752,11 @@ public TiBlob imageAsResized(Number width, Number height)
747
752
imgWidth = img .getWidth ();
748
753
imgHeight = img .getHeight ();
749
754
if (rotation != 0 ) {
755
+ if ((rotation == 90 ) || (rotation == 270 )) {
756
+ int value = dstWidth ;
757
+ dstWidth = dstHeight ;
758
+ dstHeight = value ;
759
+ }
750
760
float scaleWidth = (float ) dstWidth / imgWidth ;
751
761
float scaleHeight = (float ) dstHeight / imgHeight ;
752
762
Matrix matrix = new Matrix ();
@@ -848,10 +858,7 @@ public TiBlob imageAsThumbnail(Number size, @Kroll.argument(optional = true) Num
848
858
return null ;
849
859
}
850
860
851
- int rotation = 0 ;
852
- if (type == TYPE_FILE ) {
853
- rotation = TiImageHelper .getOrientation (getNativePath ());
854
- }
861
+ int rotation = getImageOrientation ();
855
862
856
863
int thumbnailSize = size .intValue ();
857
864
@@ -938,10 +945,8 @@ public TiBlob imageWithAlpha()
938
945
if (img == null ) {
939
946
return null ;
940
947
}
941
- int rotation = 0 ;
942
- if (type == TYPE_FILE ) {
943
- rotation = TiImageHelper .getOrientation (getNativePath ());
944
- }
948
+
949
+ int rotation = getImageOrientation ();
945
950
946
951
String nativePath = getNativePath ();
947
952
String key = null ;
@@ -995,10 +1000,7 @@ public TiBlob imageWithRoundedCorner(Number cornerRadius, @Kroll.argument(option
995
1000
return null ;
996
1001
}
997
1002
998
- int rotation = 0 ;
999
- if (type == TYPE_FILE ) {
1000
- rotation = TiImageHelper .getOrientation (getNativePath ());
1001
- }
1003
+ int rotation = getImageOrientation ();
1002
1004
1003
1005
float radius = cornerRadius .floatValue ();
1004
1006
float border = 1f ;
@@ -1059,10 +1061,7 @@ public TiBlob imageWithTransparentBorder(Number size)
1059
1061
return null ;
1060
1062
}
1061
1063
1062
- int rotation = 0 ;
1063
- if (type == TYPE_FILE ) {
1064
- rotation = TiImageHelper .getOrientation (getNativePath ());
1065
- }
1064
+ int rotation = getImageOrientation ();
1066
1065
1067
1066
int borderSize = size .intValue ();
1068
1067
0 commit comments