Skip to content

Commit 7ce3ae1

Browse files
authored
fix(android): blob imageAsX() methods to read exif for non-files (#11679)
- Was only reading JPEG EXIF orientation for file types only. Now reads for all types via InputStream. Fixes TIMOB-27872
1 parent 52d4d81 commit 7ce3ae1

File tree

1 file changed

+24
-25
lines changed
  • android/titanium/src/java/org/appcelerator/titanium

1 file changed

+24
-25
lines changed

android/titanium/src/java/org/appcelerator/titanium/TiBlob.java

+24-25
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,17 @@ private Bitmap getImage(BitmapFactory.Options opts)
614614
returnimage;
615615
}
616616

617+
privateintgetImageOrientation()
618+
{
619+
introtation = 0;
620+
try (InputStreamstream = getInputStream()) {
621+
rotation = TiImageHelper.getOrientation(stream);
622+
} catch (Exceptionex) {
623+
Log.e(TAG, "Failed to fetch image EXIF orientation from blob.", ex);
624+
}
625+
returnrotation;
626+
}
627+
617628
@Kroll.method
618629
publicTiBlobimageAsCropped(Objectparams)
619630
{
@@ -626,10 +637,7 @@ public TiBlob imageAsCropped(Object params)
626637
returnnull;
627638
}
628639

629-
introtation = 0;
630-
if (type == TYPE_FILE) {
631-
rotation = TiImageHelper.getOrientation(getNativePath());
632-
}
640+
introtation = getImageOrientation();
633641

634642
KrollDictoptions = newKrollDict((HashMap) params);
635643
intwidthCropped = options.optInt(TiC.PROPERTY_WIDTH, width);
@@ -718,13 +726,10 @@ public TiBlob imageAsResized(Number width, Number height)
718726
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
719727
}
720728

721-
StringnativePath = getNativePath();
722-
introtation = 0;
723-
if (type == TYPE_FILE) {
724-
rotation = TiImageHelper.getOrientation(nativePath);
725-
}
729+
introtation = getImageOrientation();
726730

727731
Stringkey = null;
732+
StringnativePath = getNativePath();
728733
if (nativePath != null) {
729734
key = nativePath + "_imageAsResized_" + rotation + "_" + dstWidth + "_" + dstHeight;
730735
Bitmapbitmap = mMemoryCache.get(key);
@@ -747,6 +752,11 @@ public TiBlob imageAsResized(Number width, Number height)
747752
imgWidth = img.getWidth();
748753
imgHeight = img.getHeight();
749754
if (rotation != 0) {
755+
if ((rotation == 90) || (rotation == 270)) {
756+
intvalue = dstWidth;
757+
dstWidth = dstHeight;
758+
dstHeight = value;
759+
}
750760
floatscaleWidth = (float) dstWidth / imgWidth;
751761
floatscaleHeight = (float) dstHeight / imgHeight;
752762
Matrixmatrix = newMatrix();
@@ -848,10 +858,7 @@ public TiBlob imageAsThumbnail(Number size, @Kroll.argument(optional = true) Num
848858
returnnull;
849859
}
850860

851-
introtation = 0;
852-
if (type == TYPE_FILE) {
853-
rotation = TiImageHelper.getOrientation(getNativePath());
854-
}
861+
introtation = getImageOrientation();
855862

856863
intthumbnailSize = size.intValue();
857864

@@ -938,10 +945,8 @@ public TiBlob imageWithAlpha()
938945
if (img == null) {
939946
returnnull;
940947
}
941-
introtation = 0;
942-
if (type == TYPE_FILE) {
943-
rotation = TiImageHelper.getOrientation(getNativePath());
944-
}
948+
949+
introtation = getImageOrientation();
945950

946951
StringnativePath = getNativePath();
947952
Stringkey = null;
@@ -995,10 +1000,7 @@ public TiBlob imageWithRoundedCorner(Number cornerRadius, @Kroll.argument(option
9951000
returnnull;
9961001
}
9971002

998-
introtation = 0;
999-
if (type == TYPE_FILE) {
1000-
rotation = TiImageHelper.getOrientation(getNativePath());
1001-
}
1003+
introtation = getImageOrientation();
10021004

10031005
floatradius = cornerRadius.floatValue();
10041006
floatborder = 1f;
@@ -1059,10 +1061,7 @@ public TiBlob imageWithTransparentBorder(Number size)
10591061
returnnull;
10601062
}
10611063

1062-
introtation = 0;
1063-
if (type == TYPE_FILE) {
1064-
rotation = TiImageHelper.getOrientation(getNativePath());
1065-
}
1064+
introtation = getImageOrientation();
10661065

10671066
intborderSize = size.intValue();
10681067

0 commit comments

Comments
 (0)
close