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.

5 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!

    • 3 Bhushan 2011-02-04 at 07:34:19

      Hello,

      I run your code with X-Code-3.1 version but its giving an error [NSCFArray objectAtIndex:]: index (3) beyond bounds (1)
      could you please help me to sort out this problem

  3. 4 Kathy 2013-02-28 at 07:15:27

    Seeds of Ajwain are little in size yet its taste is hot,
    bitter and penchant. Almond significantly possesses the several phytochemicals such as
    beta-sisterol, stigmasterol and compesterol. Some studies conclude that this herb can stop the growth of
    certain cancers like breast, prostate, and skin because of these antioxidants and anti-inflammatory effects.


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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s





Follow

Get every new post delivered to your Inbox.

%d bloggers like this: