GithubHelp home page GithubHelp logo

loganwright / simplecam Goto Github PK

View Code? Open in Web Editor NEW
210.0 8.0 37.0 14.36 MB

A Memory Efficient Drop In Replacement / Alternative for the Native UIImagePicker Camera

License: Mozilla Public License 2.0

Ruby 4.35% Objective-C 95.65%

simplecam's Introduction

SimpleCam

A Memory Efficient Drop In Replacement / Alternative for the Native UIImagePicker Camera

Why Do I Need It?

SimpleCam was created out of the necessity to have high quality photographs while providing a lightweight memory footprint. Apple's UIImagePicker is a wonderful application, but because it has a lot of features and a lot of options, . . . it uses a lot of MEMORY. This can cause crashes, lag, and an overall poor experience when all you wanted was to give the user an opportunity to take a quick picture.

If you're capturing photographs with UIImagePicker, or via AVFoundation on the highest possible capture resolution, it will return giant image files exceeding thousands of pixels in size. SimpleCam avoids this while still using the highest possible capture resolution by resizing the photo to 2x the size of the phone's screen. This allows the photo to maintain a significantly reduced file size while still looking clean and brilliant on mobile displays.

I hope you find the project as useful as I did!

Features

  • iOS 7 Inspired Design
  • 3.5โ€ & 4โ€ Screen Compatibility
  • Low Memory Usage
  • Drag & Drop Installation
  • Portrait/Landscape Views
  • Front/Rear Camera
  • Touch to Focus
  • Controllable Flash
  • Auto Crop / Scale
  • Selfies Don't Flip

Icons generously provided by PixelLove:

CocoaPods

pod 'SimpleCam', '~> 0.1'

#Adding SimpleCam to Your Project

###1. Add SimpleCam Folder to Xcode

  • Unzip SimpleCam
  • Drag SimpleCam Folder into your Xcode project
  • Make sure "Copy items into destination group's folder (if needed)" is selected

###2. Your ViewController.h File

  • Import SimpleCam
  • Set up your view controller as a SimpleCam delegate
#import <UIKit/UIKit.h>
#import "SimpleCam.h"

@interface ViewController : UIViewController <SimpleCamDelegate>

@end

###3. Set Up Delegate

  • Add SimpleCam's Delegate method to your ViewController.m file
  • Close SimpleCam

This is how SimpleCam will notify your ViewController that the user is finished with it. If there is an image, then the user took a picture. If there is not, then the user backed out of the camera without taking a photograph. Make sure to close SimpleCam in this method using SimpleCam's custom close. Otherwise, the captureSession may not close properly and may result in memory leaks.

#pragma mark SIMPLE CAM DELEGATE

- (void) simpleCam:(SimpleCam *)simpleCam didFinishWithImage:(UIImage *)image {
    
    if (image) {
        // simple cam finished with image
    }
    else {
        // simple cam finished w/o image
    }
    
    // Close simpleCam - use this as opposed to dismissViewController: to properly end photo session
    [simpleCam closeWithCompletion:^{
        NSLog(@"SimpleCam is done closing ... ");
        // It is safe to launch other ViewControllers, for instance, an editor here.
    }];
}

###4. Launch SimpleCam

  • Add this code wherever you'd like SimpleCam to launch
SimpleCam * simpleCam = [[SimpleCam alloc]init];
simpleCam.delegate = self;    
[self presentViewController:simpleCam animated:YES completion:nil];

If you'd like to launch simple cam when the user presses a button, you could add the above code to the buttonPress method, like so:

- (void) buttonPress:(id)sender {        
  SimpleCam * simpleCam = [[SimpleCam alloc]init];
  simpleCam.delegate = self;    
  [self presentViewController:simpleCam animated:YES completion:nil];
}

That's it, it's as simple as that. SimpleCam will take care of everything else!

#ChangeLog

v1.01 Released 19 May 2014

Thanks @capezzbr & @dkhamsing for their contributions to this commit!

  • You can now capture photos programmatically by calling [simpleCam capturePhoto]
  • Now supports an overlay control system (more interaction possibilities coming soon!)
  • Disable Photo Preview to save photos as soon as they're captured: simpleCam.disablePhotoPreview = YES
  • New delegate method to be notified of when the camera stream is visible:
- (void) simpleCamDidLoadCameraIntoView:(SimpleCam *)simpleCam {
    NSLog(@"Camera loaded ... ");
}

#Screen Shots

###Portrait

Camera (About To Capture)

Preview (Shows Captured Image)

Preview - Rotated (Maintains Captured Image Ratio)

###Landscape

Camera (About To Capture)

Preview (Shows Captured Image)

Preview - Rotated (Maintains Captured Image Ratio)

simplecam's People

Contributors

capezzbr avatar dkhamsing avatar joshbernfeld avatar loganwright avatar pcantrell avatar rad182 avatar wj2061 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplecam's Issues

Cocoapods

Hey, this looks awesome! Can we submit it to to cocoapods?

Crash invoking SimpleCam

I get this crash every time when trying to present SimpleCam:

2014-09-19 17:53:37.988 Social Stitch[73038:884614] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
0 CoreFoundation 0x000000010dfc33f5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010d905bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010deae4d3 -[__NSArrayM objectAtIndex:] + 227
3 Social Stitch 0x000000010a382829 -[SimpleCam viewDidLoad] + 2873
4 UIKit 0x000000010c2e8190 -[UIViewController loadViewIfRequired] + 738
5 UIKit 0x000000010c2e838e -[UIViewController view] + 27
6 UIKit 0x000000010c88583f -[_UIFullscreenPresentationController _setPresentedViewController:] + 65
7 UIKit 0x000000010c2c3c49 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 105
8 UIKit 0x000000010c2f4121 -[UIViewController _presentViewController:withAnimationController:completion:] + 1746
9 UIKit 0x000000010c2f6461 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 132
10 UIKit 0x000000010c2f6385 -[UIViewController presentViewController:animated:completion:] + 229
11 UIKit 0x000000011d6999de -[UIViewControllerAccessibility presentViewController:animated:completion:] + 101

This is how I am invoking it:
SimpleCam * simpleCam = [[SimpleCam alloc] init];
simpleCam.delegate = self;
[self presentViewController:simpleCam animated:YES completion:nil];

Hopefully I am just missing something simple, as this library looks great!

A possible enhancement!!!!

Hello,

Thank you very much for your fantastic tool.
Very Very nice indeed!
I have to propose only one possible enhancement....
Can you make to present the controller with a navigation bat and a toolbar...and on navigation bar to have the back button and on toolbar to have all other buttons (camera flash, rotate camera, take photo, save photo )?

This will make more usable your tool for any one that wants to integrate your tool in an app.....

Thank you very much again

George Gerardis

Handle no camera permission on iOS8

I was getting crashes if the user rejected camera permission on iOS8.
I added a simple check ahead of calling simplecam but would be great if it handled it all itself.

podspec specifies deployment version 7.1

Hey, your pod spec file specifies a deployment target of 7.1, but that creates conflicts with any pods set for version 7.0. I don't see any reason why it shouldn't include 7.0, and if there is no specific reason you chose to upgrade the target, do you mind changing the pod spec file?

AVCaptureDevice requestAccessForMediaType should explicitly call [self setup] on main thread

I was getting black screen failures when running SimpleCam on a device for the first time.

Apple's documentation for AVCaptureDevice requestAccessForMediaType says: "The completion handler is called on an arbitrary dispatch queue. Is it the client's responsibility to ensure that any UIKit-related updates are called on the main queue or main thread as a result."

Once I put this kind of stuff in:

dispatch_async(dispatch_get_main_queue(), ^{
    [self setup];
    [self animateIntoView];
});

the issue went away.

Note that it's easy to miss this, as, AFAICT, camera access is granted for the entire device even though the popup asks permission for the app. So once you've authorized the camera at all on a development device, SimpleCam's auth routines will work. But it not, not... To debug this, I ended up changing the bundle id, as this guy suggests.

Unfortunately I can't submit a pull request, as we've too heavily modified your code to work with a specific project. But hopefully this should help. SimpleCam is great. Thanks!

Expose image stabilization for AVCaptureStillImageOutput

Logan, thanks for your work on this wrapper. I've got a suggestion for an improvement. I didn't think a PR was necessary as it is pretty straightforward:

In the header file:
@Property BOOL isStabilizedMode;

In setup after the AVCaptureStillImageOutput object is created:
if (isStabilizedMode && _stillImageOutput.isStillImageStabilizationSupported) {
_stillImageOutput.automaticallyEnablesStillImageStabilizationWhenAvailable = YES;
}

This is iOS7+, so if you support older code bases it should be wrapped in a respondsToSelector

Zoom

Is it easy to add zoom in SimpleCam ?

Thanks,

Back button broken

Hi, when I tap back button in the preview photo it just shows black. Any solution?

Controls not drawing correctly on first load

The controls do not draw the images, only the text "capture", on the first load of the camera view after giving permission to the app to use the camera. It only happens on the first load after installation, but causes erroneous behavior which is very unfavorable especially if an image is used instead of capture because the user is presented with no controls. I have tried invoking [self loadControls], [self setNeedsDisplay] in view did load. Also tried [self.view bringSubviewToFront:btn]; in the load control method. I even tried asking for camera permission prior to invoking the simpleCam in the parent view controller. All to no avail. To simulate first install behavior and get the camera permission request you must uninstall app, change date of device forward more than 1 day, and than restart device.

The only way that I have gotten a "work around" is to create a flag firstTime that is set by the parent view controller which asks for camera permission before starting simpleCam. If the camera permission has just been granted the firstTime flag is set to YES. I then have simpleCam dismiss itself at the end of viewDidAppear, the parent view controller then reloads simpleCam only if the firstTime flag has been set. On the second load everything works fine. This double load only happens after the first install, but is currently the only way I can get the controls to draw.

camera setup is really slow on very first start on device

On the very first start on a device it takes maybe 20 sec or more to start up simplecam.
On the second start it opens immediately.
I tried with the demo supplied.
If I delete the app and restart it again, it is fast.

Does anybody have an idea?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.