Skip to content

Commit

Permalink
updata code
Browse files Browse the repository at this point in the history
  • Loading branch information
shabake committed Apr 10, 2019
1 parent cd54851 commit b3547de
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
44 changes: 37 additions & 7 deletions GHCameraModule/GHCameraModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ @interface GHCameraModule()<AVCaptureVideoDataOutputSampleBufferDelegate,AVCaptu

@property (nonatomic , copy) CameraModuleBlock cameraModuleBlock;
@property (nonatomic , copy) CameraModuleCodeBlock cameraModuleCodeBlock;
@property (nonatomic , copy) NSString *string;

#define weakself(self) __weak __typeof(self) weakSelf = self

Expand Down Expand Up @@ -121,23 +122,52 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:
if (metadataObjects.count > 0) {

AVMetadataMachineReadableCodeObject *metadataObject = [metadataObjects objectAtIndex :0];
NSString *string = metadataObject.stringValue;
self.string = string;
NSArray *array = metadataObject.corners;
NSLog(@"array%@",array);
CGPoint point = CGPointZero;
int index = 0;
CFDictionaryRef dict = (__bridge CFDictionaryRef)(array[index++]);
CGPointMakeWithDictionaryRepresentation(dict, &point);
CGPoint point2 = CGPointZero;
CGPointMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)array[2], &point2);
CGFloat scace = 100 /(point2.x-point.x);
NSLog(@"scacescacescace%f",scace);
[self setVideoScale:scace];
}
}

- (void)setVideoScale:(CGFloat)scale{

[self.input.device lockForConfiguration:nil];
//获取放大最大倍数
AVCaptureConnection *videoConnection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
CGFloat maxScaleAndCropFactor = ([[self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo] videoMaxScaleAndCropFactor])/16;

scale = 1.4;

videoConnection.videoScaleAndCropFactor = scale;
[CATransaction begin];
[CATransaction setAnimationDuration:0.25];
[self.previewLayer setAffineTransform:CGAffineTransformMakeScale(scale, scale)];
videoConnection.videoScaleAndCropFactor = scale;
[CATransaction commit];
[CATransaction setCompletionBlock:^{
[self.session stopRunning];
[self.input.device unlockForConfiguration];

NSString *string = metadataObject.stringValue;
if (string.length) {
NSString *resultString = metadataObject.stringValue;
if (self.string.length) {

if (self.cameraModuleCodeBlock) {
self.cameraModuleCodeBlock(resultString);
self.cameraModuleCodeBlock(self.string);
}
if (self.delegate && [self.delegate respondsToSelector:@selector(cameraModule:info:resultString:)]) {
[self.delegate cameraModule:self info:nil resultString:resultString];
[self.delegate cameraModule:self info:nil resultString:self.string];
}
}
}
}];
}

- (void)screenshot {
AVCaptureConnection * videoConnection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
if (!videoConnection) {
Expand Down
2 changes: 1 addition & 1 deletion GHCustom/GHCameraModuleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ - (void)cameraModule:(GHCameraModule *)cameraModule info:(NSDictionary *)info re

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 9_0) {

[self.cameraModule start];
// [self.cameraModule start];
}

#pragma mark - 懒加载
Expand Down

0 comments on commit b3547de

Please sign in to comment.