iPhone-Dev: Creating a Full-Screen Camera Preview, Part 2.

Damn, this blog is all about development nowadays, and to think, I told one guy I didn’t want to put his blog on my blogroll because it mostly had development stuff. Actually all it had was his “portfolio” of websites/apps he made, not bad, but not really a blog. So I said no. So he got offended. Eh, bite me, you SEO-weenie.

Well to get back to the point, like Erica, I hate the fact that the user has to click touch “Take Photo” to take a picture. I looked ather instructions, and after some a lot of struggling managed to get it to work.

But a problem was, the camera overlay would return if one returns to the camera view after leaving it, so I realized it had to go into its own view controller.

I tried improving it today, and it was really simple!

In the .h file:

@interface MyImagePickerController : UIImagePickerController {
  // Empty
}
@end

And in the .m file:

@implementation MyImagePickerController
- (void) viewDidAppear: (BOOL)animated {
  [super viewDidAppear:animated];
  UIView *plCameraView = [[[[[[self.view subviews] objectAtIndex:0] subviews] objectAtIndex:0] subviews] objectAtIndex:0];
  // [[[plCameraView subviews] objectAtIndex:3] removeFromSuperview];
  [[[plCameraView subviews] objectAtIndex:3] setHidden:YES];
}

Initializing is just like before:

  MyImagePickerController *imagePickerController = [[MyImagePickerController alloc] init];
  imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

And to capture the preview, e.g. with an NSTimer (I haven’t looked up how to fake the clicking of the “Take Photo” button):

  CGImageRef img = UIGetScreenImage();
  UIImage *grabbedImage = [UIImage imageWithCGImage:img];
  // you can now manipulate the grabbedImage;
  CFRelease(img);

Update 2009-01-17: for some reason the overlay reappears when the view is redrawn, and it doesn’t seem that viewDidAppear gets recalled. Peeking at lajos’ code, he uses the method setHidden:YES, and it works for what I did too. So I’ve “commented out” my previous code that deletes the overlay and replaced it with one that just makes the overlay – as the method tells you – hidden.

3 Responses to “iPhone-Dev: Creating a Full-Screen Camera Preview, Part 2.”


  1. 1 Lar 2009-01-03 at 11:58:39

    Hey,

    I found your site through erica’s blog. Any chance I could take a look at the source code to get this example working?

    Thanks,
    Lar

  2. 2 lajos 2009-01-12 at 06:52:24

    Hello netsharc,

    I have a small xcode project and write up to demonstrate some tweaks to the camera interface here: custom UIImagePickerController camera view.

    I used your suggestion to override the viewDidLoad method. I’ve noted that on my post.

    Thanks!


  1. 1 soymint » custom UIImagePickerController camera view Trackback on 2009-01-19 at 22:21:17

Leave a Reply




 

December 2008
M T W T F S S
« Nov   Jan »
1234567
891011121314
15161718192021
22232425262728
293031  

a

Reverse

To reverse the order of the entries (chronogical top-to-bottom), paste this into your address bar, and hit Enter: