diff --git a/ios/DocumentScannerView.m b/ios/DocumentScannerView.m index 2eb5f78..80bc1c2 100644 --- a/ios/DocumentScannerView.m +++ b/ios/DocumentScannerView.m @@ -24,7 +24,15 @@ - (void) didDetectRectangle:(CIRectangleFeature *)rectangle withType:(IPDFRectan break; } if (self.onRectangleDetect) { - self.onRectangleDetect(@{@"stableCounter": @(self.stableCounter), @"lastDetectionType": @(type)}); + NSDictionary *rectangleCoordinates = rectangle ? @{ + @"topLeft": @{ @"y": @(rectangle.bottomLeft.x + 30), @"x": @(rectangle.bottomLeft.y)}, + @"topRight": @{ @"y": @(rectangle.topLeft.x + 30), @"x": @(rectangle.topLeft.y)}, + @"bottomLeft": @{ @"y": @(rectangle.bottomRight.x), @"x": @(rectangle.bottomRight.y)}, + @"bottomRight": @{ @"y": @(rectangle.topRight.x), @"x": @(rectangle.topRight.y)}, + } : [NSNull null]; + + + self.onRectangleDetect(@{@"stableCounter": @(self.stableCounter), @"lastDetectionType": @(type), @"rectangleCoordinates": rectangleCoordinates}); } if (self.stableCounter > self.detectionCountBeforeCapture){ @@ -34,7 +42,7 @@ - (void) didDetectRectangle:(CIRectangleFeature *)rectangle withType:(IPDFRectan - (void) capture { [self captureImageWithCompletionHander:^(UIImage *croppedImage, UIImage *initialImage, CIRectangleFeature *rectangleFeature) { - if (self.onPictureTaken) { + if (self.onPictureTaken) { NSData *croppedImageData = UIImageJPEGRepresentation(croppedImage, self.quality); if (initialImage.imageOrientation != UIImageOrientationUp) { @@ -47,42 +55,42 @@ - (void) capture { NSData *initialImageData = UIImageJPEGRepresentation(initialImage, self.quality); /* - RectangleCoordinates expects a rectanle viewed from portrait, - while rectangleFeature returns a rectangle viewed from landscape, which explains the nonsense of the mapping below. - Sorry about that. + RectangleCoordinates expects a rectanle viewed from portrait, + while rectangleFeature returns a rectangle viewed from landscape, which explains the nonsense of the mapping below. + Sorry about that. */ NSDictionary *rectangleCoordinates = rectangleFeature ? @{ - @"topLeft": @{ @"y": @(rectangleFeature.bottomLeft.x + 30), @"x": @(rectangleFeature.bottomLeft.y)}, - @"topRight": @{ @"y": @(rectangleFeature.topLeft.x + 30), @"x": @(rectangleFeature.topLeft.y)}, - @"bottomLeft": @{ @"y": @(rectangleFeature.bottomRight.x), @"x": @(rectangleFeature.bottomRight.y)}, - @"bottomRight": @{ @"y": @(rectangleFeature.topRight.x), @"x": @(rectangleFeature.topRight.y)}, - } : [NSNull null]; + @"topLeft": @{ @"y": @(rectangleFeature.bottomLeft.x + 30), @"x": @(rectangleFeature.bottomLeft.y)}, + @"topRight": @{ @"y": @(rectangleFeature.topLeft.x + 30), @"x": @(rectangleFeature.topLeft.y)}, + @"bottomLeft": @{ @"y": @(rectangleFeature.bottomRight.x), @"x": @(rectangleFeature.bottomRight.y)}, + @"bottomRight": @{ @"y": @(rectangleFeature.topRight.x), @"x": @(rectangleFeature.topRight.y)}, + } : [NSNull null]; if (self.useBase64) { - self.onPictureTaken(@{ - @"croppedImage": [croppedImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength], - @"initialImage": [initialImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength], - @"rectangleCoordinates": rectangleCoordinates }); + self.onPictureTaken(@{ + @"croppedImage": [croppedImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength], + @"initialImage": [initialImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength], + @"rectangleCoordinates": rectangleCoordinates }); } else { NSString *dir = NSTemporaryDirectory(); if (self.saveInAppDocument) { dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; } - NSString *croppedFilePath = [dir stringByAppendingPathComponent:[NSString stringWithFormat:@"cropped_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]]; - NSString *initialFilePath = [dir stringByAppendingPathComponent:[NSString stringWithFormat:@"initial_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]]; + NSString *croppedFilePath = [dir stringByAppendingPathComponent:[NSString stringWithFormat:@"cropped_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]]; + NSString *initialFilePath = [dir stringByAppendingPathComponent:[NSString stringWithFormat:@"initial_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]]; - [croppedImageData writeToFile:croppedFilePath atomically:YES]; - [initialImageData writeToFile:initialFilePath atomically:YES]; + [croppedImageData writeToFile:croppedFilePath atomically:YES]; + [initialImageData writeToFile:initialFilePath atomically:YES]; - self.onPictureTaken(@{ - @"croppedImage": croppedFilePath, - @"initialImage": initialFilePath, - @"rectangleCoordinates": rectangleCoordinates }); + self.onPictureTaken(@{ + @"croppedImage": croppedFilePath, + @"initialImage": initialFilePath, + @"rectangleCoordinates": rectangleCoordinates }); } } if (!self.captureMultiple) { - [self stop]; + [self stop]; } }];