Archive for December, 2008

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.

Man of the Year…

For the fucking win…

So sad that he missed… so sad.

(via The Guardian).


 

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: