Skip to content

Commit 0188995

Browse files
committed
Merge pull request #95 from omergul123/develop
Develop
2 parents 194d18c + 7d26bf4 commit 0188995

File tree

8 files changed

+243
-183
lines changed

8 files changed

+243
-183
lines changed

LLSimpleCamera.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "LLSimpleCamera"
3-
s.version = "4.2.0"
3+
s.version = "5.0.0"
44
s.summary = "LLSimpleCamera: A simple customizable camera - video recorder control."
55
s.description = <<-DESC
66
LLSimpleCamera is a library for creating a customized camera screens similar to snapchat's. You don't have to present the camera in a new view controller. You can capture images or record videos very easily.
@@ -15,7 +15,7 @@ hides the nitty gritty details from the developer
1515
s.license = { :type => 'APACHE', :file => 'LICENSE' }
1616
s.author = { "Ömer Faruk Gül" => "[email protected]" }
1717
s.platform = :ios,'7.0'
18-
s.source = { :git => "https://github.com/omergul123/LLSimpleCamera.git", :tag => "v4.2.0" }
18+
s.source = { :git => "https://github.com/omergul123/LLSimpleCamera.git", :tag => "v5.0.0" }
1919
s.source_files = 'LLSimpleCamera/*.{h,m}'
2020
s.requires_arc = true
2121
s.framework = 'AVFoundation'
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// LLSimpleCamera+Helper.h
3+
// LLSimpleCameraExample
4+
//
5+
// Created by Ömer Faruk Gül on 20/02/16.
6+
// Copyright © 2016 Ömer Faruk Gül. All rights reserved.
7+
//
8+
9+
#import "LLSimpleCamera.h"
10+
11+
@interface LLSimpleCamera (Helper)
12+
13+
- (CGPoint)convertToPointOfInterestFromViewCoordinates:(CGPoint)viewCoordinates
14+
previewLayer:(AVCaptureVideoPreviewLayer *)previewLayer
15+
ports:(NSArray<AVCaptureInputPort *> *)ports;
16+
17+
- (UIImage *)cropImage:(UIImage *)image usingPreviewLayer:(AVCaptureVideoPreviewLayer *)previewLayer;
18+
19+
@end
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//
2+
// LLSimpleCamera+Helper.m
3+
// LLSimpleCameraExample
4+
//
5+
// Created by Ömer Faruk Gül on 20/02/16.
6+
// Copyright © 2016 Ömer Faruk Gül. All rights reserved.
7+
//
8+
9+
#import "LLSimpleCamera+Helper.h"
10+
11+
@implementation LLSimpleCamera (Helper)
12+
13+
- (CGPoint)convertToPointOfInterestFromViewCoordinates:(CGPoint)viewCoordinates
14+
previewLayer:(AVCaptureVideoPreviewLayer *)previewLayer
15+
ports:(NSArray<AVCaptureInputPort *> *)ports
16+
{
17+
CGPoint pointOfInterest = CGPointMake(.5f, .5f);
18+
CGSize frameSize = previewLayer.frame.size;
19+
20+
if ( [previewLayer.videoGravity isEqualToString:AVLayerVideoGravityResize] ) {
21+
pointOfInterest = CGPointMake(viewCoordinates.y / frameSize.height, 1.f - (viewCoordinates.x / frameSize.width));
22+
} else {
23+
CGRect cleanAperture;
24+
for (AVCaptureInputPort *port in ports) {
25+
if (port.mediaType == AVMediaTypeVideo) {
26+
cleanAperture = CMVideoFormatDescriptionGetCleanAperture([port formatDescription], YES);
27+
CGSize apertureSize = cleanAperture.size;
28+
CGPoint point = viewCoordinates;
29+
30+
CGFloat apertureRatio = apertureSize.height / apertureSize.width;
31+
CGFloat viewRatio = frameSize.width / frameSize.height;
32+
CGFloat xc = .5f;
33+
CGFloat yc = .5f;
34+
35+
if ( [previewLayer.videoGravity isEqualToString:AVLayerVideoGravityResizeAspect] ) {
36+
if (viewRatio > apertureRatio) {
37+
CGFloat y2 = frameSize.height;
38+
CGFloat x2 = frameSize.height * apertureRatio;
39+
CGFloat x1 = frameSize.width;
40+
CGFloat blackBar = (x1 - x2) / 2;
41+
if (point.x >= blackBar && point.x <= blackBar + x2) {
42+
xc = point.y / y2;
43+
yc = 1.f - ((point.x - blackBar) / x2);
44+
}
45+
} else {
46+
CGFloat y2 = frameSize.width / apertureRatio;
47+
CGFloat y1 = frameSize.height;
48+
CGFloat x2 = frameSize.width;
49+
CGFloat blackBar = (y1 - y2) / 2;
50+
if (point.y >= blackBar && point.y <= blackBar + y2) {
51+
xc = ((point.y - blackBar) / y2);
52+
yc = 1.f - (point.x / x2);
53+
}
54+
}
55+
} else if ([previewLayer.videoGravity isEqualToString:AVLayerVideoGravityResizeAspectFill]) {
56+
if (viewRatio > apertureRatio) {
57+
CGFloat y2 = apertureSize.width * (frameSize.width / apertureSize.height);
58+
xc = (point.y + ((y2 - frameSize.height) / 2.f)) / y2;
59+
yc = (frameSize.width - point.x) / frameSize.width;
60+
} else {
61+
CGFloat x2 = apertureSize.height * (frameSize.height / apertureSize.width);
62+
yc = 1.f - ((point.x + ((x2 - frameSize.width) / 2)) / x2);
63+
xc = point.y / frameSize.height;
64+
}
65+
}
66+
67+
pointOfInterest = CGPointMake(xc, yc);
68+
break;
69+
}
70+
}
71+
}
72+
73+
return pointOfInterest;
74+
}
75+
76+
- (UIImage *)cropImage:(UIImage *)image usingPreviewLayer:(AVCaptureVideoPreviewLayer *)previewLayer
77+
{
78+
CGRect previewBounds = previewLayer.bounds;
79+
CGRect outputRect = [previewLayer metadataOutputRectOfInterestForRect:previewBounds];
80+
81+
CGImageRef takenCGImage = image.CGImage;
82+
size_t width = CGImageGetWidth(takenCGImage);
83+
size_t height = CGImageGetHeight(takenCGImage);
84+
CGRect cropRect = CGRectMake(outputRect.origin.x * width, outputRect.origin.y * height,
85+
outputRect.size.width * width, outputRect.size.height * height);
86+
87+
CGImageRef cropCGImage = CGImageCreateWithImageInRect(takenCGImage, cropRect);
88+
image = [UIImage imageWithCGImage:cropCGImage scale:1 orientation:image.imageOrientation];
89+
CGImageRelease(cropCGImage);
90+
91+
return image;
92+
}
93+
94+
@end

LLSimpleCamera/LLSimpleCamera.h

+18-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ typedef enum : NSUInteger {
4848
*/
4949
@property (nonatomic, copy) void (^onError)(LLSimpleCamera *camera, NSError *error);
5050

51+
/**
52+
* Triggered when camera starts recording
53+
*/
54+
@property (nonatomic, copy) void (^onStartRecording)(LLSimpleCamera* camera);
55+
5156
/**
5257
* Camera quality, set a constants prefixed with AVCaptureSessionPreset.
5358
* Make sure to call before calling -(void)initialize method, otherwise it would be late.
@@ -143,6 +148,15 @@ typedef enum : NSUInteger {
143148
*/
144149
- (void)stop;
145150

151+
152+
/**
153+
* Capture an image.
154+
* @param onCapture a block triggered after the capturing the photo.
155+
* @param exactSeenImage If set YES, then the image is cropped to the exact size as the preview. So you get exactly what you see.
156+
* @param animationBlock you can create your own animation by playing with preview layer.
157+
*/
158+
-(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *metadata, NSError *error))onCapture exactSeenImage:(BOOL)exactSeenImage animationBlock:(void (^)(AVCaptureVideoPreviewLayer *))animationBlock;
159+
146160
/**
147161
* Capture an image.
148162
* @param onCapture a block triggered after the capturing the photo.
@@ -157,14 +171,14 @@ typedef enum : NSUInteger {
157171
-(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *metadata, NSError *error))onCapture;
158172

159173
/*
160-
* Start recording a video. Video is saved to the given url.
174+
* Start recording a video with a completion block. Video is saved to the given url.
161175
*/
162-
- (void)startRecordingWithOutputUrl:(NSURL *)url;
176+
- (void)startRecordingWithOutputUrl:(NSURL *)url didRecord:(void (^)(LLSimpleCamera *camera, NSURL *outputFileUrl, NSError *error))completionBlock;
163177

164178
/**
165-
* Stop recording video with a completion block.
179+
* Stop recording video.
166180
*/
167-
- (void)stopRecording:(void (^)(LLSimpleCamera *camera, NSURL *outputFileUrl, NSError *error))completionBlock;
181+
- (void)stopRecording;
168182

169183
/**
170184
* Attaches the LLSimpleCamera to another view controller with a frame. It basically adds the LLSimpleCamera as a

0 commit comments

Comments
 (0)