How can i take two consecutive pictures in iOS 5 - objective-c

I'm very new at iOS and Objective C and I'm trying to design something that it requires to take two consecutive pictures (and save them both) And just learned how to use the camera in iOS 5, so I was wondering how to implement something like that.
I need to be able to open the camera, take a picture, save it and then automatically follows with the camera again to take another picture
P.D. I've been using this to use the camera:
- (void) useCamera
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
newMedia = YES;
}
}

hint: Use AVCaptureDevice, AVCaptureDeviceInput, AVCaptureStillImageOutput, AVCaptureSession.

these 2 links might be helpful. I am fairly new to iOS programing myself but this looks like something promising
How fast can iPhone to be programmed take 2 pictures at one time?
iPhone SDK 4 AVFoundation - How to use captureStillImageAsynchronouslyFromConnection correctly?

Related

how to switch camera mode to video mode using GPUImage in ios

I am making app like Instagram .i am using GPUImage framework ,in this i have to take photos and videos and share. i able to capture photos using this framework and now i have to capture video but i am struggling how to change camera mode photos to video. any help and tutorial then its very good for me. I used this code camera for photos mode.
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
self.imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
self.overlayView.frame = self.imagepicker.cameraOverlayView.frame;
self.imagepicker.cameraOverlayView = self.overlayView;
self.overlayView = nil;
CGSize result = [[UIScreen mainScreen] bounds].size;
self.imagepicker.showsCameraControls = NO;
self.imagepicker.allowsEditing = NO;
self.imagepicker.wantsFullScreenLayout = NO;
// self.imagepicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
}
else{
self.imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
In my case, I'm using GPUImage to do both (pictures and videos). Therefore I've created two objects: one of type GPUImageStillCamera(pictures) and other of type GPUImageVideoCamera (videos).
So whenever you need to switch between cameras you basically stop the GPUImageStillCamera capture and initialize a video camera (note that you have to adapt this snippet to your project):
func initializeVideoCamera() {
// Stop the capture of GPUImageStillCamera
stillCamera.stopCameraCapture()
videoCamera = GPUImageVideoCamera.init(sessionPreset: AVCaptureSessionPreset1920x1080, cameraPosition: .Back)
videoCamera?.outputImageOrientation = .Portrait
videoCamera?.addTarget(filter)
// If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
unlink(pathToMovieFile)
initializeWriteWithPath(pathToMovieFile)
videoCamera?.startCameraCapture()
}

Xcode 4.5 Black Screen or Exception: 'A view can only be associated with at most one view controller at a time!'

I have an existing iPhone app that was working fine in Xcode 4.0 prior to upgrading to Xcode 4.5. Upon upgrading, now I get a Black Screen when running in the iPhone/iPad 4.3 Simulator and get the following Exception when running the iPhone/iPad 6.0 Simulator.
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View <CCGLView: 0x8c7f380; frame = (0 0; 320 480); layer = <CAEAGLLayer: 0x8c7f670>> is associated with <CCDirectorDisplayLink = 0x994c7f0 | Size: 320 x 480, view = <CCGLView: 0x8c7f380; frame = (0 0; 320 480); layer = <CAEAGLLayer: 0x8c7f670>>>. Clear this association before associating this view with <RootViewController: 0x8c7ef00>.'
The app is using Cocos2D 2.0, and is pretty simple based on a tutorial found online. There is no XIB file. Everything is being done programmatically.
These are the lines that cause the exception in the 6.0 Simulator (from IOS6TestAppDelegate.m):
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
[enter link description here][1]viewController.wantsFullScreenLayout = YES;
If these lines are commented out, then the 6.0 Simulator shows a black screen as well, instead of the regular menu screen.
I've searched online for solutions on this and tried a number of things, but have been unable to make progress. I'm fairly new to iPhone programming (though am not new to programming in general) and am really struggling with this. I would really appreciate any help.
First, delete
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
Then replace
[window setRootViewController:viewController];
With
if( ! [director enableRetinaDisplay:YES] )
CCLOG(#"Retina Display Not supported");
// Create a Navigation Controller with the Director
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:director];
navController.navigationBarHidden = YES;
NSString *reqSysVer = #"6.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
[window setRootViewController:navController];
} else
{
[window addSubview: navController.view];
}
That should do it!

Image filtering effects using BradLarson / GPUImage ** Issue

I want to add different effects to an UIImage. Currently I am trying with using GUIImage library. https://github.com/BradLarson/GPUImage
But, I am unable to run most of the examples provided. Only working example for me is FilterShowcase It works great.
But the problem is, its work only with camera. What i want is Load an static image on to a UIImageView and apply those filters.
I tried, but unable to do it.
This is how I tried it
- (void)setupFilter;
{
// videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
//// videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionFront];
// videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 350)];
imgView.Image=[UIImage imageNamed:#"WID-small.jpg"];
[self.view addSubview:imgView];
BOOL needsSecondImage = NO;
switch (filterType)
{
case GPUIMAGE_SEPIA:
{
self.title = #"Sepia Tone";
self.filterSettingsSlider.hidden = NO;
[self.filterSettingsSlider setValue:1.0];
[self.filterSettingsSlider setMinimumValue:0.0];
[self.filterSettingsSlider setMaximumValue:1.0];
filter = [[GPUImageSepiaFilter alloc] init];
sourcePicture = [[GPUImagePicture alloc] initWithImage:imgView.image smoothlyScaleOutput:YES];
[sourcePicture processImage];
[sourcePicture addTarget:filter];
}; break;
Actually what I tried to do is, Load a still image instead of videoCamera. But it doesn't work.
If anyone can help me, its highly appreciated.
First, there are a couple of reasons why the other sample applications might not be building for you. As is stated in this answer, make sure that you have the scheme for the application selected in the upper left of your Xcode window, not the GPUImage framework project. If changing that doesn't help, exit out of Xcode, delete the relevant project directories from your DerivedData directory, and restart Xcode. That sometimes seems to be needed due to a bug in recent Xcode versions.
The filtering of an image is described in the documentation for the project, which is in the Readme.md file and on the page you link above. In particular, see the section titled "Processing a still image":
There are a couple of ways to process a still image and create a
result. The first way you can do this is by creating a still image
source object and manually creating a filter chain:
UIImage *inputImage = [UIImage imageNamed:#"Lambeau.jpg"];
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];
[stillImageSource addTarget:stillImageFilter];
[stillImageSource processImage];
UIImage *currentFilteredVideoFrame = [stillImageFilter imageFromCurrentlyProcessedOutput];
For single filters that you wish to apply to an image, you can simply
do the following:
GPUImageSepiaFilter *stillImageFilter2 = [[GPUImageSepiaFilter alloc] init];
UIImage *quickFilteredImage = [stillImageFilter2 imageByFilteringImage:inputImage];
The SimpleImageFilter example application shows how to do this in more detail.

Show camera shutter programmatically?

In order to make my custom UIImagePickerSourceTypeCamera, I had to do this:
pickerOne = [[UIImagePickerController alloc] init];
pickerOne.delegate = self;
pickerOne.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerOne.showsCameraControls = NO;
pickerOne.navigationBarHidden = YES;
pickerOne.toolbarHidden = YES;
pickerOne.wantsFullScreenLayout = YES;
But now, when I take a picture like this:
[cameraButton addTarget:pickerOne
action:#selector(takePicture)
forControlEvents:UIControlEventTouchUpInside];
it doesn't show the shutter when you take the picture. Is there a way to show it programmatically?
It is possible. The trick is to do the following:
Enable the camera controls on initializing the picker (this will enable the shutter view).
pickerOne.showsCameraControls = YES;
Overlay the camera controls with your own view which has the cameraButton
In your takePicture: method do the following:
pickerOne.showsCameraControls = NO;
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.0]];
[pickerOne takePicture];
In the imagePickerController:didFinishPickingMediaWithInfo: method do the following:
pickerOne.showsCameraControls = YES; // perform on main thread
There is no way to control the "shutter" affect. You can however create your own image and add the affect in there.

Slight pause in scrolling animation (iPad)

I am relatively new to programming on the iPad and I was trying to put together a simple program. Basically, it's a children's book and I need the functionality of a comic book style (or photo) viewer, where people swipe to change "pages" (or images).
Each image is 1024x768. Currently, they are stored as JPGs because of the very large file sizes PNGs seem to produce. For this story, there are 28 pages.
I took a look at the PageControl example, implementing a UIScrollView. On initialization, I create a big enough scrollview area. Then as the user scrolls, I load in the previous and next images. Again, just like the example only without implementing the page control at the bottom.
The problem I am running into is a very slight pause in the animation when I am flipping. Once the images are loaded or cached, this doesn't happen. Now, I know the photo application doesn't do this and I'm not sure what is causing it.
Here is my code for the scrollViewDidScroll method. I keep up with the page number and it will only call the loadPageIntoScrollView when a page has changed - I was thinking that the insane number of calls it was making was causing the slight pause in animation, but it turned out not to be the case.
- (void) scrollViewDidScroll: (UIScrollView *) sender
{
CGFloat pageWidth = scrollView.frame.size.width;
int localPage = floor( (scrollView.contentOffset.x - pageWidth / 2 ) / pageWidth ) + 1;
if( localPage != currentPage )
{
currentPage = localPage;
[self loadPageIntoScrollView:localPage - 1];
[self loadPageIntoScrollView:localPage];
[self loadPageIntoScrollView:localPage + 1];
}
} // scrollViewDidScroll
And here is my loadPageIntoScrollView method. I'm only creating a UIImageView and loading an image into that - I don't see how that could be much "leaner". But somehow it's causing the pause. Again, it's not a HUGE pause, just one of those things you notice and is enough to make the scrolling look like it has a very. very slight hiccup.
Thank you in advance for any help you could provide.
- (void) loadPageIntoScrollView: (int)page
{
if( page < 0 || page >= kNumberOfPages )
return;
UIImageView *controller = [pages objectAtIndex:page];
NSLog( #"checking pages" );
if( (NSNull *)controller == [NSNull null] )
{
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleSingleTap:)];
NSString *pageName = [[NSString alloc] initWithFormat:#"%d.jpg", page];
controller = [[UIImageView alloc]initWithImage:[UIImage imageNamed:pageName]];
[controller setUserInteractionEnabled:YES];
[controller addGestureRecognizer:singleTap];
[pages replaceObjectAtIndex:page withObject:controller];
[controller release];
} // if controller == null
// add the page to the scrollview
if( controller.superview == nil )
{
NSLog(#"superview was nil, adding page %d", page );
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.frame = frame;
[scrollView addSubview:controller];
} // if
} // loadPageIntoScrollView
Since you say after an image is loaded in it no longer lags, I'd suspect that it is disk access that is causing your lag, but you should run your app through instruments to try to rule out cpu-spikes as well as evaluate file system usage. You may try to pre-load images to the left and right of whatever image you are on so that the user doesn't perceive as much lag.
First off, you should be able to use PNG's just fine. I have build several apps that do exactly what you are doing here, you can fit 3 1024 x 768 PNGs in memory without running out (but you can't do much more). You should also use PNG's as they are the preferred format for iOS as they are optimized when the app is bundled together during build.
The slight lag is caused by loading the image, in this line:
controller = [[UIImageView alloc]initWithImage:[UIImage imageNamed:pageName]];
What I usually do is load the images in a separate thread, using something like this:
[self performSelectorInBackground:#selector(loadPageIntoScrollView:) withObject:[NSNumber numberWithInt:localPage]];
Note that you need to put your localPage integer into a NSNumber object to pass it along, so don't forget to change your loadPageIntoScrollView: method:
- (void) loadPageIntoScrollView: (NSNumber *)pageNumber
{
int page = [pageNumber intValue];
....