Skip to content

Commit 4dfce4d

Browse files
committed
Changed default behaviour to pass uri instead of base64 via onPictureTaken
For performance reasons.
1 parent 1b70ed1 commit 4dfce4d

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

ios/DocumentScannerView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@property (nonatomic, assign) NSInteger detectionCountBeforeCapture;
99
@property (assign, nonatomic) NSInteger stableCounter;
1010
@property (nonatomic, assign) float quality;
11+
@property (nonatomic, assign) BOOL useBase64;
1112

1213
- (void) capture;
1314

ios/DocumentScannerView.m

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ - (void) didDetectRectangle:(CIRectangleFeature *)rectangle withType:(IPDFRectan
3434

3535
- (void) capture {
3636
[self captureImageWithCompletionHander:^(UIImage *croppedImage, UIImage *initialImage, CIRectangleFeature *rectangleFeature) {
37-
38-
if (self.onPictureTaken) {
37+
if (self.onPictureTaken) {
3938
NSData *croppedImageData = UIImageJPEGRepresentation(croppedImage, self.quality);
4039

4140
if (initialImage.imageOrientation != UIImageOrientationUp) {
@@ -58,10 +57,24 @@ - (void) capture {
5857
@"bottomLeft": @{ @"y": @(rectangleFeature.bottomRight.x), @"x": @(rectangleFeature.bottomRight.y)},
5958
@"bottomRight": @{ @"y": @(rectangleFeature.topRight.x), @"x": @(rectangleFeature.topRight.y)},
6059
} : [NSNull null];
61-
self.onPictureTaken(@{
62-
@"croppedImage": [croppedImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength],
63-
@"initialImage": [initialImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength],
64-
@"rectangleCoordinates": rectangleCoordinates });
60+
61+
if (self.useBase64) {
62+
self.onPictureTaken(@{
63+
@"croppedImage": [croppedImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength],
64+
@"initialImage": [initialImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength],
65+
@"rectangleCoordinates": rectangleCoordinates });
66+
} else {
67+
NSString *croppedFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"cropped_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]];
68+
NSString *initialFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"initial_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]];
69+
70+
[croppedImageData writeToFile:croppedFilePath atomically:YES];
71+
[initialImageData writeToFile:initialFilePath atomically:YES];
72+
73+
self.onPictureTaken(@{
74+
@"croppedImage": croppedFilePath,
75+
@"initialImage": initialFilePath,
76+
@"rectangleCoordinates": rectangleCoordinates });
77+
}
6578
}
6679
[self stop];
6780
}];

ios/RNPdfScannerManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ - (dispatch_queue_t)methodQueue
2222
RCT_EXPORT_VIEW_PROPERTY(overlayColor, UIColor)
2323
RCT_EXPORT_VIEW_PROPERTY(enableTorch, BOOL)
2424
RCT_EXPORT_VIEW_PROPERTY(useFrontCam, BOOL)
25+
RCT_EXPORT_VIEW_PROPERTY(useBase64, BOOL)
2526
RCT_EXPORT_VIEW_PROPERTY(detectionCountBeforeCapture, NSInteger)
2627
RCT_EXPORT_VIEW_PROPERTY(detectionRefreshRateInMS, NSInteger)
2728
RCT_EXPORT_VIEW_PROPERTY(saturation, float)

0 commit comments

Comments
 (0)