changed so we use the cropToPreview parameter to crop the image
This commit is contained in:
parent
19286de6be
commit
da1f0f2fdd
|
@ -13,9 +13,10 @@ const styles = StyleSheet.create({
|
|||
flex: 1,
|
||||
},
|
||||
preview: {
|
||||
flex: 1,
|
||||
alignSelf: "stretch",
|
||||
justifyContent: 'flex-end',
|
||||
alignItems: 'center',
|
||||
height: 200
|
||||
},
|
||||
overlay: {
|
||||
position: 'absolute',
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
|
@ -22,12 +22,25 @@
|
|||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSExceptionDomains</key>
|
||||
<dict>
|
||||
<key>localhost</key>
|
||||
<dict>
|
||||
<key>NSExceptionAllowsInsecureHTTPLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>This app needs access to the camera to take photos.</string>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string>This app needs access to the location to geolocalize your captures.</string>
|
||||
<string></string>
|
||||
<key>NSMicrophoneUsageDescription</key>
|
||||
<string>This app needs access to the microphone to take videos.</string>
|
||||
<key>NSPhotoLibraryAddUsageDescription</key>
|
||||
<string>Your message to user when the photo library is accessed for the first time</string>
|
||||
<key>NSPhotoLibraryUsageDescription</key>
|
||||
<string>This app needs access to the photo library to save your captures.</string>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
|
@ -39,24 +52,10 @@
|
|||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string></string>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<!--See http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ -->
|
||||
<dict>
|
||||
<key>NSExceptionDomains</key>
|
||||
<dict>
|
||||
<key>localhost</key>
|
||||
<dict>
|
||||
<key>NSExceptionAllowsInsecureHTTPLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -16,8 +16,7 @@ typedef NS_ENUM(NSInteger, RCTCameraCaptureSessionPreset) {
|
|||
RCTCameraCaptureSessionPresetPhoto = 3,
|
||||
RCTCameraCaptureSessionPreset480p = 4,
|
||||
RCTCameraCaptureSessionPreset720p = 5,
|
||||
RCTCameraCaptureSessionPreset1080p = 6,
|
||||
RCTCameraCaptureSessionPresetPreview = 7
|
||||
RCTCameraCaptureSessionPreset1080p = 6
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, RCTCameraCaptureMode) {
|
||||
|
@ -72,11 +71,11 @@ typedef NS_ENUM(NSInteger, RCTCameraTorchMode) {
|
|||
@property (nonatomic, assign) NSInteger videoTarget;
|
||||
@property (nonatomic, assign) NSInteger orientation;
|
||||
@property (nonatomic, assign) BOOL mirrorImage;
|
||||
@property (nonatomic, assign) BOOL cropToPreview;
|
||||
@property (nonatomic, strong) NSArray* barCodeTypes;
|
||||
@property (nonatomic, strong) RCTPromiseResolveBlock videoResolve;
|
||||
@property (nonatomic, strong) RCTPromiseRejectBlock videoReject;
|
||||
@property (nonatomic, strong) RCTCamera *camera;
|
||||
@property (nonatomic, assign) BOOL cropToViewport;
|
||||
|
||||
|
||||
- (void)changeOrientation:(NSInteger)orientation;
|
||||
|
|
|
@ -106,8 +106,7 @@ RCT_EXPORT_MODULE();
|
|||
@"720p": @(RCTCameraCaptureSessionPreset720p),
|
||||
@"AVCaptureSessionPreset1280x720": @(RCTCameraCaptureSessionPreset720p),
|
||||
@"1080p": @(RCTCameraCaptureSessionPreset1080p),
|
||||
@"AVCaptureSessionPreset1920x1080": @(RCTCameraCaptureSessionPreset1080p),
|
||||
@"preview": @(RCTCameraCaptureSessionPresetPreview)
|
||||
@"AVCaptureSessionPreset1920x1080": @(RCTCameraCaptureSessionPreset1080p)
|
||||
},
|
||||
@"CaptureTarget": @{
|
||||
@"memory": @(RCTCameraCaptureTargetMemory),
|
||||
|
@ -141,7 +140,6 @@ RCT_EXPORT_VIEW_PROPERTY(onFocusChanged, BOOL);
|
|||
RCT_EXPORT_VIEW_PROPERTY(onZoomChanged, BOOL);
|
||||
|
||||
RCT_CUSTOM_VIEW_PROPERTY(captureQuality, NSInteger, RCTCamera) {
|
||||
self.cropToViewport = false;
|
||||
NSInteger quality = [RCTConvert NSInteger:json];
|
||||
NSString *qualityString;
|
||||
switch (quality) {
|
||||
|
@ -167,10 +165,6 @@ RCT_CUSTOM_VIEW_PROPERTY(captureQuality, NSInteger, RCTCamera) {
|
|||
case RCTCameraCaptureSessionPreset480p:
|
||||
qualityString = AVCaptureSessionPreset640x480;
|
||||
break;
|
||||
case RCTCameraCaptureSessionPresetPreview:
|
||||
qualityString = AVCaptureSessionPresetPhoto;
|
||||
self.cropToViewport = true;
|
||||
break;
|
||||
}
|
||||
|
||||
[self setCaptureQuality:qualityString];
|
||||
|
@ -300,6 +294,10 @@ RCT_CUSTOM_VIEW_PROPERTY(mirrorImage, BOOL, RCTCamera) {
|
|||
self.mirrorImage = [RCTConvert BOOL:json];
|
||||
}
|
||||
|
||||
RCT_CUSTOM_VIEW_PROPERTY(cropToPreview, BOOL, RCTCamera) {
|
||||
self.cropToPreview = [RCTConvert BOOL:json];
|
||||
}
|
||||
|
||||
RCT_CUSTOM_VIEW_PROPERTY(barCodeTypes, NSArray, RCTCamera) {
|
||||
self.barCodeTypes = [RCTConvert NSArray:json];
|
||||
}
|
||||
|
@ -630,6 +628,15 @@ RCT_EXPORT_METHOD(hasFlash:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRej
|
|||
// create cgimage
|
||||
CGImageRef cgImage = CGImageSourceCreateImageAtIndex(source, 0, NULL);
|
||||
|
||||
// Crop it (if capture quality is set to preview)
|
||||
if (self.cropToPreview) {
|
||||
CGSize viewportSize = CGSizeMake(self.previewLayer.frame.size.width, self.previewLayer.frame.size.height);
|
||||
CGRect captureRect = CGRectMake(0, 0, CGImageGetWidth(cgImage), CGImageGetHeight(cgImage));
|
||||
CGRect croppedSize = AVMakeRectWithAspectRatioInsideRect(viewportSize, captureRect);
|
||||
|
||||
cgImage = CGImageCreateWithImageInRect(cgImage, croppedSize);
|
||||
}
|
||||
|
||||
// Rotate it
|
||||
CGImageRef rotatedCGImage;
|
||||
if ([options objectForKey:@"rotation"]) {
|
||||
|
@ -659,15 +666,6 @@ RCT_EXPORT_METHOD(hasFlash:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRej
|
|||
rotatedCGImage = cgImage;
|
||||
}
|
||||
|
||||
// Crop it (if capture quality is set to preview)
|
||||
if (self.cropToViewport) {
|
||||
CGSize viewportSize = CGSizeMake(self.previewLayer.frame.size.width, self.previewLayer.frame.size.height);
|
||||
CGRect captureRect = CGRectMake(0, 0, CGImageGetWidth(rotatedCGImage), CGImageGetHeight(rotatedCGImage));
|
||||
CGRect croppedSize = AVMakeRectWithAspectRatioInsideRect(viewportSize, captureRect);
|
||||
|
||||
rotatedCGImage = CGImageCreateWithImageInRect(rotatedCGImage, croppedSize);
|
||||
}
|
||||
|
||||
// Erase stupid TIFF stuff
|
||||
[imageMetadata removeObjectForKey:(NSString *)kCGImagePropertyTIFFDictionary];
|
||||
|
||||
|
|
Loading…
Reference in New Issue