samedi 17 mars 2012

Custom Camera Applications Development Using Iphone Sdk

iPhone contains many helpful features. One of these can be build-in photographic camera as well as Camera program program pertaining to generating photos. It seems to be good but think about photographic camera utilization with indigenous applications? iPhone SDK offers the actual capability involving using camcorder through UIImagePickerController class. Thats great nonetheless the good news is tiny disadvantage - you should not create a full-screen continual reside camera check out such as the Camera application does. Instead of that you must use UIImagePickerController only inside modal function - indicate your pop-up modal perspective when you need a image and close the watch following your photo can be made. You must reopen the following perspective for a second time to look at the subsequent one.

Moreover, which modal check out includes more energy and also adjustments this overlay the p articular digital camera view. Another weakness is usually - you should not require a photography in a touch; you might want to touch the actual Shoot switch for taking some sort of photograph and preview it, then you might want to feel this Save switch to have the photo for processing. Probably it is the top training but I dont as it as well as I expect you would imagine similar way.



What regarding while using the UIImagePickerController as a good ordinal non-modal check out controlled below the navigation controller the identical approach while we all use the opposite look at controllers? Try that and you will observed that it works! The camera check out works and appears to be while it should. You could assign a delegate in addition to method UIImagePickerControllerDelegate events to get along with spend less the actual photo. Ok, effect the actual Shoot button, touch the Save switch - great, youve acquired that photo! But just simply have a look at this specific - this Retake and Save links reside above this digicam view, and in addition they dont do the job these days if they usually are touched This happens because you should not totally reset the particular view to look at a further picture once using one plus in contact the actual Save button, that view can be freezed along with the links are disabled. It seems you'll want to totally recreate the particular UIImagePickerController instance to consider another photo. Thats not so straightforward and never and so good. And you will always must utilize solar panels plus links in which overlay that digital camera view



Now I include a good idea! When we effect Shoot, that view stops relaxing along with displays sole impression in the camera; in that case we must hint Retake or Save button. Can we all acquire which picture as well as conserve the item without resorting to the UIImagePickerContro llerDelegate and then contact the Retake option programmatically to reset to zero that perspective to get yet another photo? Sure most people can! If anyone examine the actual digital camera views hierarchy after touching Shoot you'll find that you will find there's undetectable perspective associated with ImageView type. This school is not explained within the SDK, but we could explore its strategies implementing Objective-C capabilities. We can easily see how the school posesses a approach called imageRef. Lets do this Yes, them profits CGImage object! And this photo dimension is 1200 times 1600 - it has the absolutely this camera picture!



Ok, now most people know we can get the photograph not having UIImagePickerControllerDelegate. But around what instant will need to most people do this? Can most people catch a computer owner splashes to the Shoot press button to start processing? Its feasibl e and not and so good. Do everyone remember some of our main goal making the persistent full-screen digital camera view similar to system Camera software does? Its moment to do it! When we visited the actual ideas hierarchy, weve discovered that will you will find quantity of landscapes over this camera view. We can endeavor to cover these kinds of views along with make our personal control key listed below the particular photographic camera view to help take the particular picture in one touch. But how should we all induce the particular camera look at to create the particular photo? Its not difficult - we can obtain communicating selector in the Shoot button and call them through our activity handler!



Ok, weve obligated having the image. But it will require all of us handful of seconds. How might we all detect that this photo is definitely ready? It happened should the Cancel along with Shoot links are replaced by Retake plus Save ones. The most straig htforward way to identify this particular is actually commencing a timer with quick time period and verifying your buttons. And after that we are able to have and help you save the photo, while using corresponding selector from the Retake option as well as phoning that to reset the actual digital camera look at plus make the item to generate a new one. Here will be code:



// Shot option to the toolbar touched. Make your photo.
- (void)shotAction:(id)sender {
[self enableInterface:NO];
// Simulate effect to the Image Picker's Shot button
UIControl *camBtn = [self getCamShutButton];
[camBtn sendActionsForControlEvents:UIControlEventTouchUpInside];

// Set upward timer for you to check the camera settings to diagnose should the image
// on the camcorder might be prepared.
// Image Picker's Shot option is handed down since userInfo that will compare with latest button.
[NSTimer scheduledTimerWithTimeInterval:0. 2 target:self selector:@selector(savePhotoTimerFireMethod:) userInfo:camBtn repeats:NO];
}

// Return Image Picker's Shoot option (the option in which would make the photo).
- (UIControl*) getCamShutButton {

UIView *topView = [self findCamControlsLayerView:self.view];
UIView *buttonsBar = [topView.subviews objectAtIndex:2];
UIControl *btn = [buttonsBar.subviews objectAtIndex:1];

return btn;
}

// Return Image Picker's Retake control key that will appears following your user pressed Shoot.
- (UIControl*) getCamRetakeButton {

UIView *topView = [self findCamControlsLayerView:self.view];
UIView *buttonsBar = [topView.subviews objectAtIndex:2];
UIControl *btn = [buttonsBar.subviews objectAtIndex:0];

return btn;
}

// Find your look at which features the digital camera equipment (buttons)
- (UIView*)findCamControlsLayerView:(UIView*)view {

Class cr aigslist = [view class];
NSString *desc = [cl description];
if ([desc compare:@"PLCropOverlay"] == NSOrderedSame)
return view;

for (NSUInteger i = 0; post < [view.subviews count]; i++)
{
UIView *subView = [view.subviews objectAtIndex:i];
subView = [self findCamControlsLayerView:subView];
if (subView)
return subView;
}

return nil;
}

// Called by simply the particular timer. Check the video camera controls in order to diagnose that the actual image is actually ready.
- (void)savePhotoTimerFireMethod:(NSTimer*)theTimer {

// Compare present-day Image Picker's Shot button with passed.
UIControl *camBtn = [self getCamShutButton];
if (camBtn != [theTimer userInfo])
{
// The button replaced by means of Save button - that picture is ready.
[self saveImageFromImageView];

// Simulate contact on Retake switch to go on working; this photographic camera is actually willing to require fresh photo.
camBtn = [self getCamRetakeButton];
[camBtn sendActionsForControlEvents:UIControlEventTouchUpInside];

[self enableInterface:YES];
}
else
{
NSTimeInterval period of time = [theTimer timeInterval];
[NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(savePhotoTimerFireMethod:) userInfo:camBtn repeats:NO];
}
}

// Save taken image out of covered graphic view.
- (BOOL)saveImageFromImageView {

UIView *cameraView = [self.view.subviews objectAtIndex:0];
if ([self enumSubviewsToFindImageViewAndSavePhoto:cameraView])
return YES;

return NO;
}

// Recursive enumerate subviews to find disguised . picture watch plus help you save photo
- (BOOL)enumSubviewsToFindImageViewAndSavePhoto:(UIView*)view {

Class clist = [view class];
NSString *desc = [cl description];
if ([desc compa re:@"ImageView"] == NSOrderedSame)
return [self grabPictureFromImageView:view];

for (int when i = 0; my partner and i < [view.subviews count]; i++)
{
if ([self enumSubviewsToFindImageViewAndSavePhoto:[view.subviews objectAtIndex:i]])
return YES;
}

return NO;
}

// Grab the particular image coming from concealed picture view plus save this photo
- (BOOL)grabPictureFromImageView:(UIView*)view {

CGImageRef img = (CGImageRef)[view imageRef];
if (img)
{
// Taken image was in UIImageOrientationRight orientation
UIImage *photo = [self correctImageOrientation:img];
UIImageWriteToSavedPhotosAlbum(photo, nil, nil, nil);

return YES;
}

return NO;
}

// Correct impression angle coming from UIImageOrientationRight (rotate with ninety degrees)
- (UIImage*)correctImageOrientation:(CGImageRef)image {

CGFloat size = CGImageGetWidth (image);
CGFloat elevation = CGImageGetHeight(image);
CGRect range = CGRectMake(0.0f, 0.0f, width, height);

CGFloat boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;

CGAffineTransform transform = CGAffineTransformMakeTranslation(height, 0.0f);
transform = CGAffineTransformRotate(transform, M_PI / 2.0f);

UIGraphicsBeginImageContext(bounds.size);

CGContextRef framework = UIGraphicsGetCurrentContext();

CGContextScaleCTM(context, - 1.0f, 1.0f);
CGContextTranslateCTM(context, -height, 0.0f);
CGContextConcatCTM(context, transform);

CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, width, height), image);

UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return imageCopy;
}



Another important question is: in just what exactly moment might many of us hide this overlaying camcorder opinions as well as equipment and also produce our very own button? Trying this viewDidLoad Oops The digicam look at is actually nonetheless possibly not created. Trying that viewWillAppear The same factor Trying your viewDidAppear Yes, this ideas have been produced allowing it to always be invisible now. Ok, we conceal that will and develop a toolbar with each of our Shoot button. It works, though the screen flicks - most people notice how the normal landscapes and also switches will be shown and then hidden. How can we keep this? I tried using several means and also have found the best one: we ought to obscure the actual sights just before there're included with the camera view (when the actual addSubview method in the digital camera view can be called). Its likely implementing Objective-C ability f or you to change the fashion dynamically at run-time. Ok, lets upgrade the addSubview by means of our personal method. In our own approach you can easlily look at how the handed down watch is on the list of camcorder check out subviews along with arranged it has the disguised . property or home for you to YES. So, most of us replace the actual addSubview in that viewWillAppear before the digicam view will be created. And most people develop our own toolbar along with Shoot option in the viewDidAppear after your digicam view is created. Take a peek at this code below:



// Replace "addSubview:" if labeled primary time; disguise camera controls otherwise.
- (void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];

if (toolBar != nil)
{
// The view ended up being undoubtedly appeared; all of us don't really need to subclass UIView
// but have to have to he lp hide additional camcorder controls.
UIView *cameraView = [self findCamControlsLayerView:self.view];
if (cameraView)
{
cameraView = cameraView.superview;
int cnt = [cameraView.subviews count];
if (cnt >= 4)
{
for (int i = 2; my spouse and i < cnt - 1; i++)
{
UIView *v = [cameraView.subviews objectAtIndex:i];
v.hidden = YES;
}
}
}
}
else
{
// Subclass UIView and also upgrade addSubview in order to obscure your camcorder perspective controls on fly.
[RootViewController exchangeAddSubViewFor:self.view];
}
}

// Exchange addSubview: of UIView class; placed our personal myAddSubview instead
+ (void)exchangeAddSubViewFor:(UIView*)view {

SEL addSubviewSel = @selector(addSubview:);
Method originalAddSubviewMethod = class_getInstanceMethod([view class], addSubviewSel);

SEL myAddSubviewSel = @selector(myAddSubview:);
Method rep lacedAddSubviewMethod = class_getInstanceMethod([self class], myAddSubviewSel);

method_exchangeImplementations(originalAddSubviewMethod, replacedAddSubviewMethod);
}

// Add the subview to be able to view; "self" details into the mother or father view.
// Set "hidden" that will YES in the event the subview will be the photographic camera regulates view.
- (void) myAddSubview:(UIView*)view {

UIView *parent = (UIView*)self;

BOOL done = NO;
Class cl . = [view class];
NSString *desc = [cl description];

if ([desc compare:@"PLCropOverlay"] == NSOrderedSame)
{
for (NSUInteger i = 0; my partner and i < [view.subviews count]; i++)
{
UIView *v = [view.subviews objectAtIndex:i];
v.hidden = YES;
}

done = YES;
}

[RootViewController exchangeAddSubViewFor:parent];

[parent addSubview:view];

if (!done)
[RootViewController exchan geAddSubViewFor:parent];
}



The technique identified on top of appeared to be used in iUniqable practical application available from Apple App Store (Social Networking section). Feel no cost to be able to use.



Feel no cost to see your site of the programmer www.enterra-inc.com



Aucun commentaire:

Enregistrer un commentaire