6
6
import android .graphics .BitmapFactory ;
7
7
import android .graphics .Matrix ;
8
8
import android .graphics .Point ;
9
+ import android .net .Uri ;
9
10
import android .util .Log ;
10
11
11
12
import androidx .annotation .NonNull ;
@@ -107,6 +108,11 @@ public void detectFile(String filePath, String template,Promise promise) {
107
108
}
108
109
WritableNativeArray returnResult = new WritableNativeArray ();
109
110
try {
111
+ File file = new File (filePath );
112
+ if (file .exists () == false ) { //convert uri to path
113
+ Uri uri = Uri .parse (filePath );
114
+ filePath = uri .getPath ();
115
+ }
110
116
CapturedResult capturedResult = cvr .capture (filePath ,templateName );
111
117
for (CapturedResultItem quad :capturedResult .getItems ()) {
112
118
returnResult .pushMap (Utils .getMapFromDetectedQuadResult ((DetectedQuadResultItem ) quad ));
@@ -125,6 +131,11 @@ public void rotateFile(String filePath, int degrees, Promise promise) {
125
131
bitmap = rotateBitmap (bitmap ,degrees ,false ,false );
126
132
File file = new File (filePath );
127
133
try {
134
+ if (file .exists () == false ) { //convert uri to path
135
+ Uri uri = Uri .parse (filePath );
136
+ filePath = uri .getPath ();
137
+ file = new File (filePath );
138
+ }
128
139
FileOutputStream fOut = new FileOutputStream (file );
129
140
bitmap .compress (Bitmap .CompressFormat .JPEG , 100 , fOut );
130
141
fOut .flush ();
@@ -164,6 +175,11 @@ public void normalizeFile(String filePath, ReadableMap quad, ReadableMap config,
164
175
}
165
176
Log .d ("DDN" ,templateName );
166
177
try {
178
+ File file = new File (filePath );
179
+ if (file .exists () == false ) { //convert uri to path
180
+ Uri uri = Uri .parse (filePath );
181
+ filePath = uri .getPath ();
182
+ }
167
183
ReadableArray points = quad .getArray ("points" );
168
184
Quadrilateral quadrilateral = new Quadrilateral ();
169
185
quadrilateral .points = convertPoints (points );
@@ -178,9 +194,9 @@ public void normalizeFile(String filePath, ReadableMap quad, ReadableMap config,
178
194
if (config .getBoolean ("saveNormalizationResultAsFile" )) {
179
195
File cacheDir = mContext .getCacheDir ();
180
196
String fileName = System .currentTimeMillis () + ".jpg" ;
181
- File file = new File (cacheDir ,fileName );
182
- new ImageManager ().saveToFile (result .getImageData (),file .getAbsolutePath (),true );
183
- returnResult .putString ("imageURL" ,file .getAbsolutePath ());
197
+ File output = new File (cacheDir ,fileName );
198
+ new ImageManager ().saveToFile (result .getImageData (),output .getAbsolutePath (),true );
199
+ returnResult .putString ("imageURL" ,output .getAbsolutePath ());
184
200
}
185
201
}
186
202
if (config .hasKey ("includeNormalizationResultAsBase64" )) {
0 commit comments