Thursday, October 4, 2012

Camera integration in iPhone

- Rashid Khaleefa
Overview:
Blog on how to integrate camera into iPhone application.
You can easily include camera feature into any ios application provided the device has a camera support, and you make use of the imagePickerController of apple.

Camera integration:
You have to create a secondary view controller for managing the overlap view to the camera.
This customises the way how the camera screen should apper once camera is initiated from your application.
Use the apples imagepickerController to pic the image snaped.
Creating overlayViewController
  1. Declare the needed controlls in .h file
  2. Implement those in .m
  3. Include the UIImagePickerControllerDelegate
  4. Create needed delegates for your overlayViewController
A Sample overlay having buttons takepicture button and done button with actions takePhoto, close respectively for those. Also the delegate methods didTakePicture, the method where you get the snaped picture and didFinshWithCamera that can be used to perform any action once you are done with camera.

The .h file of overlayViewController:

@protocol OverlayViewControllerDelegate;
@interface OverlayViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
{
id <OverlayViewControllerDelegate> delegate;
UIImagePickerController *imagePickerController;
@private
UIBarButtonItem *takePictureButton;
UIBarButtonItem *cancelButton;
}

@property (nonatomic, assign) id <OverlayViewControllerDelegate> delegate;
@property (nonatomic, retain) UIImagePickerController *imagePickerController;

@property (nonatomic, retain) IBOutlet UIBarButtonItem *takePictureButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *cancelButton;

- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType;

// camera page (overlay view)
- (IBAction)done:(id)sender;
- (IBAction)takePhoto:(id)sender;
@end

@protocol OverlayViewControllerDelegate
- (void)didTakePicture:(UIImage *)picture;
- (void)didFinishWithCamera;
@end

Now in you .m file, Initiate the imagePickerController and map its delegate

self.imagePickerController = [[[UIImagePickerController alloc] init] autorelease];
self.imagePickerController.delegate = self;

- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType
{
NSLog(@"enters setupImagePicker");
self.imagePickerController.sourceType = sourceType;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
// user wants to use the camera interface
//
self.imagePickerController.showsCameraControls = NO;
if ([[self.imagePickerController.cameraOverlayView subviews] count] == 0)
{
// setup your custom overlay view for the camera
//
// ensure that your custom view's frame fits within the parent frame
CGRect overlayViewFrame = self.imagePickerController.cameraOverlayView.frame;
CGRect newFrame = CGRectMake(0.0,
CGRectGetHeight(overlayViewFrame) -
self.view.frame.size.height - 10.0,
CGRectGetWidth(overlayViewFrame),
self.view.frame.size.height + 10.0);
self.view.frame = newFrame;
[self.imagePickerController.cameraOverlayView addSubview:self.view];
}
}
}

This calls the didFinishWithCamera delegats.

- (IBAction)done:(id)sender
{
[self.delegate didFinishWithCamera];
}

Action that maps takesPhoto. This just calls the takePicture of imgaePickerController which is responsible for initiating still image capture.

- (IBAction)takePhoto:(id)sender
{
[self.imagePickerController takePicture];
}

Also include the follwoing delegates of imgePicker which gets called when an image is taken by the camera.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
if (self.delegate)
[self.delegate didTakePicture:image];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self.delegate didFinishWithCamera]; // tell your delegate we are finished with the picker
}
Thats all for overlayViewController

Now How to use this in your class. You have to now include the overlayController delegate and imgaPickerController in header of the class where you wish to inclue a button for a camera capture.
Now call the below function in the button action you need.

- (void)showImagePicker:(UIImagePickerControllerSourceType)sourceType
{
NSLog(@"entered showImagePicker camera");
if ([UIImagePickerController isSourceTypeAvailable:sourceType])
{
[self.overlayViewController setupImagePicker:sourceType];
[self presentModalViewController:self.overlayViewController.imagePickerController animated:YES];
}
}

This checks for the sourcetype you give that should be a camera sourcetype the syntax is as below

[self showImagePicker:UIImagePickerControllerSourceTypeCamera];

Thats it now include the delegates of overlay class that was created

- (void)didTakePicture:(UIImage *)picture
{
//do some thing with the picture.
}
- (void)didFinishWithCamera
{
[self dismissModalViewControllerAnimated:YES];
}

The didTakePicture tells that a picture was taken, you get the picture you snapped in this delegate. And didFinishWithCamera tells to finish with the camera.
Thats it. You get your camera to snap from your application and the image you snapped. 

52 comments:

Unknown said...

Teradata Training in Hyderabad and Bangalore with live projects by experts, will help you with strong foundation with terada operations.

Richard Majece said...

It's really interesting that I found info https://resumecvwriter.com/blog/how-to-write-a-cover-letter when I had to write my cover letter. Now I can use it every time in order to get a high grade.

Julie T. Kirwan said...

green farm 3 mod bully anniversary edition mod
https://mxplayerpro.xyz/apk/

SamantaWriter said...

buy essay, try this once, and you will understand why that`s so good

Quickbooks Support said...

Thanks for the instructions on camera integration in I-phone; the description about undergoing the steps is very good, and the coding which is mentioned is very useful for support.
Keep sharing and posting.
Note to readers: If you want Intuit Support for your QuickBooks accounting software then instantly get in touch with our professionals to resolve your queries and problems.

repairtechsolutions said...

Did you build this website yourself? online google pixel display repair Please reply back as I’m wanting to create my own personal site and would like to find out where you got this from or what the theme is online nokia display repair called. Thanks! I really like it whenever people get together and share opinions. Great blog, keep it up! Very online iphone display repair good info.

repairtechsolutions said...

Lucky me I discovered your blog by chance online mi display repair (stumbleupon). I have book-marked it for later! This website was... how do you say it? Relevant!! Finally, I online lg display repair have found something that helped me. Thanks! Everything is very open with a very clear clarification of the online mobile repair marathahalli challenges.

Delhi Escorts said...

I am Shreya Sehgal in Delhi Escorts. I am one of the top international models, and escorting is my profession and passion. I love being around handsome guys and of course, make some money out of it. I always take my career seriously and have been in the profession for a long time. So, if you want to have fun before pursuing to other areas of the country, ping me. I have fallen in love with the lifestyle; I am living and always enjoy it. I never look for a significant number of bookings and a perfect overnight booking is sufficient for me. I am sure to keep you engaged for the whole night with my finely crafted entertainment skills. I know that a deeper understanding of the client leads to much more fulfilling experience and thus, I hold a sensual discussion with the client and then do everything, which I need to do in a bid to satisfy him. In the escorting industry, experience speaks volumes. I am too young but I know what I am expected to do to satisfy you with ultimate fun. I am open for any style or pose, you desire for the most satisfying sex. I am ready for inbound or outbound calls and you can connect to me anytime.
Visit My Websites
Delhi Escorts Service
Delhi Call Girls
Independent Escorts in Delhi
Female Escorts in Delhi
Hyderabad Escorts

meldaresearch said...

It is important for college nursing students to seek help with nursing writing services from a reputable custom nursing research paper service company so as to be assured of good grades in their nursing research paper services.

sammer mark said...

Awesome post. I simply stumbled upon your weblog and wanted to mention that I have really loved surfing around your blog posts. If you are facing problem regarding HP Printer in Error State Windows 10. Their are very few and simple steps by our experts. Call our Toll-Free number or visit our website for more details or any information. We are available 24 x 7.

sammer mark said...

Awesome post.If you are facing problem regarding HP Printer Setup. Their are very few and simple steps by our experts. Call our Toll-Free number or visit our website for more details or any information. We are available 24 x 7.

sammer mark said...

Now a day it is very common issues regarding the How to Fix Epson Printer Error e-01, installation or setup of the new printer call us for troubleshooting you HP Printer related any issues or setup. Our team is always available for you at any time by certified expert. Thank you for the post.

Dakota Leest said...

Very interesting article. I want to write an article about the war. A difficult topic. I need help. I want help from qualified writers such as this site https://bestwritingservice.com/writing-literary-analysis.html.

Mike77 said...

If you want your essay to be ideal, you should contact the article and essay service to help you with it. www.essay-company.com/

master papers said...

I study as a programmer, but the topic of writing an essay will still be relevant for me until the end of my studies. The service of essay writing helped me finally pass the perfect writing work, for which I get excellent marks. If you have time, explore the site Master Papers

Sammer mark said...

Great site. Continue posting progressively instructive articles like these one. These are generally excellent articles HP printer regarding the problem solve it at home. Call our HP support Toll-Free number.
Fix My HP Envy 7855 Printer Offline Issues
Fix Epson Printer Error-e01 Code

augustwalker said...

HP deskjet 3630 setup Guide for windows and Mac OS. 123hpcom dj3630 Printer wifi Connection.Wireless Setup Wizard, WPS Setup.

Jolene said...

Thanks for the topic. I was just looking for an answer. It also helps me Expert Writers to solve issues related to education. I am pleased with the service.

sammer mark said...

Thanks for sharing this post with us. If you have any questions regarding any peripheral devices like printer Support, laptop issues,etc then get instant solution by our experts at anytime.
Steps to Scan Without Scanner by Expert
Steps to Make a Printer Available on a Wifi Network

Pushba said...

Thanks for sharing.
IELTS Coaching in chennai

German Classes in Chennai

GRE Coaching Classes in Chennai

TOEFL Coaching in Chennai

spoken english classes in chennai | Communication training

Anonymous said...

Thanks for sharing..
Android Training in Bangalore

Android Training

Android Online Training

Android Training in Hyderabad

Android Training in Chennai

Android Training in Coimbatore

jdgvks said...

Thanks for sharing..
hadoop training in bangalore

oracle training in bangalore

hadoop training in acte.in/oracle-certification-training">oracle training

oracle online training

oracle training in hyderabad

hadoop training in chennai

ramya devi said...

awesome post done by author. If you have any problem regarding the Printer or any other peripherals tdevices call us or visit our official website anytime. We feel proud to help you.

DevOps Training in Bangalore

DevOps Training

DevOps Online Training


DevOps Training in Hyderabad

DevOps Online Training in Chennai

DevOps Training in Coimbatore

Steven Salvatore said...


123.hp.com/setup - Complete Hp Printer setup, Driver Software installation, 123 hp com wireless setup & Troubleshooting 123hpcom Printer.

Maria Julia said...

In today's world where CCTV is a huge appeal, it becomes difficult for users to choose a perfect camera for their use. When it comes to home security and surveillance, Arlo is the first name that comes to mind. From different options to choose from, Arlo login has given various advantages to its user in many ways. The only thing we need is home security cameras to protect ourselves from intruders, burglars, and robbers. And to keep oneself safe from loot, Arlo by Netgear has given high-end features to its users by providing one of the best cameras. Arlo camera login has given all the solutions to its users which they were afraid of.

https://247camerahelp.com/arlo-pro-login/

Steven Salvatore said...

If you are facing ink system failure Problem then visit this blog to Fix HP Ink System Failure In HP Printers.

Hope James said...

The scenario-based elearning are of different types, which include simple scenario-based learning, complex scenario-based learning, one-shot scenario-based learning, learn-by-example scenario-based learning, and microworlds. Moreover, clients from different industries avail of the scenario based elearning services without thinking twice about it, which includes service providers, marketing, ed-tech companies, and manufacturing.

Firmware File said...

Flash file is used to upgrade, downgrade or reinstall the operating system in your mobile. If you facing any software problem like the application stopped working, the phone not working and an IMEI issue, you can download the firmware file to fix the issue.
Micromax yu5010 flash file

Axel Smith said...

hi, i am axel smith i am reading your blog, it is amazing blog thanks for the sharing the blog. Crazy For Study provide the Earth Science Textbook Solution Manuals online such as a information about education for students queries. Crazy For Study also provide the marine Calculus Textbook Solution Manuals. students from different walks of life can afford our assignment help services as we are affordable. moreover, our team of academic writers is highly efficient at their work.

Marcel Mikaelson said...

Rapid urbanization, along with increasing consumer preference for cross-functional devices, is one of the key factors driving the growth of the laptop battery market.

Derek Lafortune said...

A useful guide. thanks for sharing it! I think it will be needed by many developers who develop iOS applications. I also want to share an even easier way: Import UIImagePickerControllerDelegate and create a variable to assign UIImagePickerController var imagePicker = UIImagePickerController () and set imagePicker.delegate = self. Create an action sheet to display the 'Camera' and 'Photo library' parameters. Click on the action button. I gathered this information from posts on Instagram in which iOS developers tell how to effectively code in Swift. I managed to find a lot of such posts there and I noticed that in most cases they had about 30 thousand likes! I am sure this is because their authors have resorted to using the services https://viplikes.net/buy-instagram-likes to quickly increase the number of likes.

Mike Johnson said...

Why don't you make a video about this camera integration and post it on youtube? You can buy youtube subscribers for your profile if you are going to post many such video

Quickbooks error said...

In the apparatus center point select Installation Issues. You can likewise look at these articles for more data. Press multiple times on the QuickBooks PC introduce Diagnostic tools to run the Install diagnostic tool quickbooks.

Seo Spot Agency said...

One of the reason to read this Blog is your quality of content that you've used on this Blog. SeoSpot Agency

Shopon.pk said...

This is one of the best description of this really interesting topic, I've ever read on any Blog. Assignment Help Writers

AsanBazaar.PK said...

This is absolutely well written blog, I found very rare blogs with such informative content on this topic. Asan Bazaar

SS Web Solution said...

These days SEO (search engine optimization) is playing a very important part to rank your website on search engines on a related search to be seen and visited by the audience it's getting hard day by day because of tough competition I should recommend getting SEO services to grow your business online.

Divya said...

Thank you so much for the blog.
Java Training Institute in Chennai
Learn Java Online
Java Training Institutes in Bangalore

Ravindra Sharma said...

Great blog, it is very impressive.

Clinical SAS Course in Chennai
Clinical SAS Online Course

Divya said...

Thank you so much for blog. Keep sharing more.
Python Training in Chennai
Python Online Course
Python Training in Bangalore

AjithAk said...

Thanks for sharing valuable information,
Salesforce Course in Chennai
Salesforce Training Online
Salesforce Course in Bangalore

Rosy S said...

I have read your whole post it's very informative:
Software Testing Course in Chennai
Software Testing Online Course
Software Testing Course in Coimbatore

Rosy S said...

Great post. keep sharing such a worthy information.
Java Training in Chennai
Java Online Course
Java Training in Coimbatore

Divya said...

thank you for the blog. keep sharing more.
Python Classes in Chennai
Python Classes Near Me
Best Python Training in Bangalore

Rosy S said...

Nice blog with good content and thanks for sharing!!
Android Training in Chennai
Android Online Course
Android Training in Coimbatore

Divya said...

great blog. keep sharing more.
Testing Courses In Chennai
Software Testing Institute Near Me
Software Testing Training Institute in Coimbatore

Essien said...


Its amazing article; thank you so much for sharing this auspicious interesting ideas. You’re an excessively skilled review. Thanks so much for sharing. aau cut off mark for Dentistry

neha said...

SEO Company in Pakistan offer a wide range of services aimed at improving a website's visibility and ranking on search engines like Google. Blogger commenting is one of the many tactics that these companies may use as part of their overall SEO strategy.

Lakshmanan said...

Thanks for sharing blog this post is wonderful....
interview questions on tableau
tableau interview questions and answers
tableau interview questions for experienced
tableau server interview questions
tableau real time interview questions
tableau interview questions pdf

Amanda Rossie Tech said...

Great blog, this is such a cool content on this blog. Such a nice way to describe such interesting facts in this Blog. Primo Capital Real Estate Dubai Should be share/recommends to other platforms too.

Sumathu said...

Nice Blog

UI UX Design Course in Chennai
Learn UI UX Online
UI UX Design Course in Coimbatore

Best Fence Company in North Virginia said...

Immerse your property in timeless elegance with our expert wood fence installation services. We specialize in crafting wooden fences that not only secure your space but also enhance its natural beauty.