Saturday, 1 June 2013

Custom Camera Applications Development Using Iphone Sdk

Custom Camera programs development using apple iphone SDK


apple iphone consists of many helpful features. One of these is build-in camera and Camera application system to make photos. It appears great but how about camera usage with native programs? apple iphone SDK offers the capacity of utilizing camera through UIImagePickerController class. That’s great but there’s a little disadvantage – you can’t produce a full-screen persistent “live” camera view such as the Camera application does. Rather than that you ought to use UIImagePickerController only in modal mode – show the pop-up modal view when you really need a photograph and shut the vista following the photo is created. You need to reopen this view again to accept next one.


Furthermore, that modal view consists of additional sections and controls that overlay your camera view. Another disadvantage is – you can’t have a photo in a single touch you have to touch the Shoot button to consider an image and preview it, and you have to touch the Save button to obtain the photo for processing. Most likely it is the best practice however i can’t stand it and I think you’ll think exactly the same way.


How about while using UIImagePickerController being an ordinal non-modal view controller underneath the navigation controller exactly the same way once we make use of the other view remotes? Check it out and you’ll discovered that it really works! Your camera view works and appears because it should. You are able to assign a delegate and process UIImagePickerControllerDelegate occasions to obtain and save the photo. Ok, touch the Shoot button, touch the Save button – great, you have the photo! But simply see this – the Retake and Save buttons stay over the camera view, and they are not effective now when they’re touched… It is because you can’t totally reset the vista to consider another photo after taking one and touching the Save button, the vista is freezed and also the buttons are disabled. It appears you have to fully recreate the UIImagePickerController instance to consider another photo. That isn’t so easy and not too good. But you just want to use the sections and buttons that overlay your camera view…


Now I know! Whenever we touch Shoot, the vista stops refreshing and shows single image from you then we must touch Retake or Save button. Are we able to have that image and save it without needing the UIImagePickerControllerDelegate after which touch the Retake button programmatically to totally reset the vista and obtain another photo? Sure we are able to! Should you explore your camera sights hierarchy after touching Shoot you will notice that there’s a concealed look at ImageView type. These kinds isn’t referred to within the SDK, but we are able to explore its’ techniques using Objective-C abilities. We are able to observe that the category consists of a technique known as imageRef. Let us do this… Yes, it returns CGImage object! And also the image dimensions are 1200 x 1600 – it’s certainly your camera picture!


Ok, now we all know we are able to obtain the photo without UIImagePickerControllerDelegate. However in what moment don’t let do that? Are we able to catch the consumer touches around the Shoot button to begin processing? It is possible although not so great. Remember our primary purpose – allowing the persistent full-screen camera view like system Camera application does? You’re ready to get it done! Whenever we investigated the sights hierarchy, we have discovered that you will find quantity of sights over the camera view. We are able to attempt to hide these sights and make our very own button underneath the camera view to accept photo in a single touch. But exactly how should we pressure your camera view to help make the photo? It is extremely simple – we are able to obtain the corresponding selector in the Shoot button and refer to it as from your action handler!


Ok, we have forced obtaining the image. However it takes us couple of seconds. Exactly how should we identify the image is prepared? It happened once the Cancel and Shoot buttons are changed by Retake and Save ones. The easiest method to identify this really is beginning a timer with short interval and checking the buttons. Therefore we could possibly get and save the photo, while using corresponding selector in the Retake button and calling it to totally reset your camera view and make preparations it to make a replacement. This is actually the code:


// Shot button around the plugin touched. Result in the photo.


- (void)shotAction:(id)sender identify once the image


// from you is going to be prepared.


// Image Picker’s Shot button is passed as userInfo to check with current button.


[NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(savePhotoTimerFireMethod:) userInfo:camBtn repeats:NO]


// Return Image Picker’s Shoot button (the button which makes the photo).


- (UIControl*) getCamShutButton


// Return Image Picker’s Retake button that seems following the user pressed Shoot.


- (UIControl*) getCamRetakeButton


// Discover the view that consists of your camera controls (buttons)


- (UIView*)findCamControlsLayerView:(UIView*)view


return nil


// Called through the timer. Look into the camera controls to detect the image is prepared.


- (void)savePhotoTimerFireMethod:(NSTimer*)theTimer


else


// Save taken image from hidden image view.


- (BOOL)saveImageFromImageView


// Recursive enumerate subviews to locate hidden image view and save photo


- (BOOL)enumSubviewsToFindImageViewAndSavePhoto:(UIView*)view


return NO


// Grab the look from hidden image view and save the photo


- (BOOL)grabPictureFromImageView:(UIView*)view


return NO


// Correct image orientation from UIImageOrientationRight (rotate on 90 degrees)


- (UIImage*)correctImageOrientation:(CGImageRef)image


Another essential real question is: with what moment are we able to hide the overlaying camera views and controls and make our very own button? Using the viewDidLoad… Oops… Your camera view continues to be not created. Using the viewWillAppear… Exactly the same thing… Using the viewDidAppear… Yes, the views happen to be created and could be hidden now. Ok, we hide that and make up a toolbar with this Shoot button. It really works, however the screen flicks – we have seen the way the standard views and buttons are provided after which hidden. Exactly how should we prevent this? I attempted various ways coupled with found the very best one: we ought to hide the views before they’re put into your camera view (once the addSubview approach to your camera view is known as). It is possible using Objective-C capacity to switch the method dynamically at run-time. Ok, let’s switch the addSubview by our very own method. Within our method we are able to make sure that the passed view is among the camera view subviews and hang its’ “hidden” property to YES. So, we switch the addSubview within the viewWillAppear prior to the camera view is made. And that we create our toolbar and Shoot button within the viewDidAppear following the camera view is made. Check out the code below:


// Replace “addSubview:” if called very first time hide camera controls otherwise.


- (void)viewWillAppear:(BOOL)animated


else


// Exchange addSubview: of UIView class set our very own myAddSubview instead


+ (void)exchangeAddSubViewFor:(UIView*)view


// Add some subview to see “self” suggests parents view.


// Set “hidden” to YES when the subview may be the camera controls view.


- (void) myAddSubview:(UIView*)view


done = YES


[RootViewController exchangeAddSubViewFor:parent]


[parent addSubview:view]


if (!done)


[RootViewController exchangeAddSubViewFor:parent]


The work was made as Navigation-Based Application. Please observe that all of the implementation files were renamed from *.m to *.mm to create their Objective-C++ rather than Objective-C since i prefer C++.


The strategy described above was utilized in iUniqable application offered by Apple App Store (Social Media section). You can utilize.


You can go to the website from the developer






via RKB Digital Media http://www.rkbdigitalmedia.com/custom-camera-applications-development-using-iphone-sdk/

No comments:

Post a Comment