@@ -87,7 +87,17 @@ export var takePicture = function (options?): Promise<any> {
87
87
trace . write ( `An error occurred while scanning file ${ picturePath } : ${ ex . message } !` , trace . categories . Debug ) ;
88
88
}
89
89
}
90
- } ;
90
+ }
91
+
92
+ let exif = new android . media . ExifInterface ( picturePath ) ;
93
+ let orientation = exif . getAttributeInt ( android . media . ExifInterface . TAG_ORIENTATION , android . media . ExifInterface . ORIENTATION_NORMAL ) ;
94
+ if ( orientation === android . media . ExifInterface . ORIENTATION_ROTATE_90 ) {
95
+ rotateBitmap ( picturePath , 90 ) ;
96
+ } else if ( orientation === android . media . ExifInterface . ORIENTATION_ROTATE_180 ) {
97
+ rotateBitmap ( picturePath , 180 ) ;
98
+ } else if ( orientation === android . media . ExifInterface . ORIENTATION_ROTATE_270 ) {
99
+ rotateBitmap ( picturePath , 270 ) ;
100
+ }
91
101
92
102
let asset = new imageAssetModule . ImageAsset ( picturePath ) ;
93
103
asset . options = {
@@ -133,4 +143,22 @@ var createDateTimeStamp = function () {
133
143
date . getMinutes ( ) . toString ( ) +
134
144
date . getSeconds ( ) . toString ( ) ;
135
145
return result ;
146
+ }
147
+
148
+ var rotateBitmap = function ( picturePath , angle ) {
149
+ try {
150
+ let matrix = new android . graphics . Matrix ( ) ;
151
+ matrix . postRotate ( angle ) ;
152
+ let bmOptions = new android . graphics . BitmapFactory . Options ( ) ;
153
+ let oldBitmap = android . graphics . BitmapFactory . decodeFile ( picturePath , bmOptions ) ;
154
+ let finalBitmap = android . graphics . Bitmap . createBitmap ( oldBitmap , 0 , 0 , oldBitmap . getWidth ( ) , oldBitmap . getHeight ( ) , matrix , true ) ;
155
+ let out = new java . io . FileOutputStream ( picturePath ) ;
156
+ finalBitmap . compress ( android . graphics . Bitmap . CompressFormat . JPEG , 100 , out ) ;
157
+ out . flush ( ) ;
158
+ out . close ( ) ;
159
+ } catch ( ex ) {
160
+ if ( trace . isEnabled ( ) ) {
161
+ trace . write ( `An error occurred while rotating file ${ picturePath } (using the original one): ${ ex . message } !` , trace . categories . Debug ) ;
162
+ }
163
+ }
136
164
}
0 commit comments