[iPhone] Uncovering the Secrets of UIImagePickerController Part 2

With that view hierarchy information, I make change to the views. To remove the “Take Picture” words from the viewfinder, and the following code to the viewDidAppear: method:

Instead of removing them by using removeFromSuperView, I hide. It is not advisable to remove or replace them because the these views contain components that may be used by other objects (e.g. PLCropOverlay, PLCameraView, etc). By the way, you can also use this technique to remove hide the buttons (hint: /0/0/0/3). I followed lajos‘s example and start a timer when Camera button is clicked. The timer will invoke a function, which checks the /0/0/0/2 UIView. When the image is ready, /0/0/0/2 will contain subviews. To skip the confirmation screen, I just have to retrieve the image and dismiss the UIImagePickerController. How do I retrieve the image?

On Air Source blog, Gee mentioned the use of UIGetScreenImage(), which is an undocumented function in the SDK. UIGetScreenImage() does a printscreen and returns a CGImageRef. Well, it works, but it is not really a good solution. The screen size is 360×480, but the image that the camera produces is 1200×1600. Is it possible to get the original image produced by the camera?

Every view has a Core Animation layer. I am unable to retrieve the original UIImage/CGImageRef, but I can get the CALayer to draw out the 1200×1600 image. When the image is ready, use the following code to create an image:

This is a better solution, compared to the usage of UIGetScreenImage(). The former does not use any undocumented SDK feature (except for retrieving the view /0/0/0/2/0/0/0).

Part 1 | Part 3

WARNING: Readers are adviced not to use the techniques presented in this 3 parts series. It is against the terms stated in the iPhone Developer Program. When undocumented features are used, the application may not work when a newer iPhone OS is released.DO IT AT YOUR OWN RISK.

Posted in Tao Of Programming at June 12th, 2009. 2 Comments.