Thursday, January 5, 2012

UIImagePickerController and a Simple Example

iPhone's camera is really fun for me.
Here is my note about UIImagePickerController and a simple example.


Three ways to pick image
//Pick from Camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

//Pick from all folders in the gallery
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

//Pick from PhotosAlbum(camera roll)
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

Check camera's existence
//Check Camera available or not
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])

//Check PhotoLibrary available or not
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) 

//Check front Camera available or not
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])

UIImagePickerControllerDelegate protocol
//Tells the delegate that the user picked a still image or movie.
 (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
}

//Tells the delegate that the user cancelled the pick operation.
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
}

//Tells the delegate that the user picked an image. (Deprecated in iOS 3.0. Use imagePickerController:didFinishPickingMediaWithInfo: instead.)
- (void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingImage:(UIImage *)image 
  editingInfo:(NSDictionary *)editingInfo
{
}


A simple basic camera code example:
(UIKit,Foundation,CoreGraphics)

ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate>

@property(nonatomic,retain)IBOutlet UIImageView *imageView;
@property(nonatomic,retain)IBOutlet UIBarButtonItem *saveImageBotton;

-(IBAction)showCameraAction:(id)sender;
-(IBAction)saveImageAction:(id)sender;

@end
Protocol UIImagePickerController and UINavigationController.
UIImagePickerController is a subclass of the UINavigationController.
UIImageView can't show video,need to use MPMoviePlayer instance(Property view).

ViewController.m
#import "ViewController.h"

@implementation ViewController

@synthesize imageView;
@synthesize saveImageBotton;

#pragma mark - Show camera

-(IBAction)showCameraAction:(id)sender
{
    UIImagePickerController *imagePickController=[[UIImagePickerController alloc]init];
    imagePickController.sourceType=UIImagePickerControllerSourceTypeCamera;
    imagePickController.delegate=self;
    imagePickController.allowsEditing=TRUE;
    [self presentModalViewController:imagePickController animated:YES];
    [imagePickController release];
}

#pragma mark - Save photo

-(IBAction)saveImageAction:(id)sender
{
    UIImage *image=imageView.image;
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    saveImageBotton.enabled=FALSE;
}

#pragma mark - When finish shoot

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image=[info objectForKey:UIImagePickerControllerEditedImage];
    imageView.image=image;
    saveImageBotton.enabled=TRUE;
    [self dismissModalViewControllerAnimated:YES];
}

#pragma mark - Release object

- (void)dealloc {
    [imageView release];
    [saveImageBotton release];
    [super dealloc];
}

#pragma mark

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
 // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
 [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
 [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

@end


PS1:
According to the following,you can set imageView Mode
imageView.contentMode = UIViewContentModeScaleAspectFit;
you can set it to any of the following

UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit,
UIViewContentModeScaleAspectFill,
UIViewContentModeRedraw,
UIViewContentModeCenter,
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight


PS2:
[Other Properties]
cameraCaptureMode
--->UIImagePickerControllerCameraCaptureModePhoto(Default) or UIImagePickerControllerCameraCaptureModeVideo

cameraDevice
--->UIImagePickerControllerCameraDeviceFront or UIImagePickerControllerCameraDeviceRear(Default)

cameraFlashMode
--->Close:UIImagePickerControllerCameraFlashModeOff = -1
--->Auto:UIImagePickerControllerCameraFlashModeAuto = 0 (Default)
--->Open:UIImagePickerControllerCameraFlashModeOn = 1

cameraOverlayView
--->about Customized

68 comments:

  1. Excellent post! Thanks!

    ReplyDelete
  2. I agree. This post made it very easy to add the camera to my app.

    ReplyDelete
  3. Thanks alott !! Nice post !!

    ReplyDelete
  4. Hi Hanpo do i have to create a Xib file and wire up the actions and iboutlets?

    can you tell me what i should put in the Xib file

    ReplyDelete
  5. COMMON QUESTIONS ABOUT PRODUCTS vimax
    Who should not drink obat vimax? Yes what age? Vimax is safe for consumption all men of age 17-74 years.
    Does vimax asli side effects? No ... vimax made by the team physician experienced through research and clinical trials over the years. For more than 11 years in circulation, vimax reportedly did not cause any side effects.
    Do vimax canada safe for people with diabetes, hypertension, hypotension, heart, kidneys? Very secure at all, because vimax made of herbal ingredients. besides it can also help reduce other diseases.
    Does vimax obat pembesar penis create dependency? No, when we have reached the stage of maximum and we are satisfied with the results vimax, we can stop taking it.
    Does vimax pembesar penis can make allergies? Not unless you are indeed allergic to the content that is in vimax.

    ReplyDelete
  6. cara menggugurkan kandungan banyak sekali jenisnya dari non medis ( alami ) dan medis.
    Tapi cara apakah yang paling aman dan baik bagi wanita untuk minum obat aborsi

    ReplyDelete
  7. My relatives always say that I am wasting my time here at web, but I know I am getting know-how all the time by reading such nice content.
    jual obat aborsi
    obat aborsi jakarta
    obat aborsi surabaya
    obat aborsi bali

    ReplyDelete
  8. Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading.
    obat aborsi cytotec

    ReplyDelete
  9. I simply want to tell you that I am new to weblog and definitely liked this blog site. Very likely I’m going to bookmark your blog . You absolutely have wonderful stories. Cheers for sharing with us your blog cute good morning images

    ReplyDelete
  10. I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally. Im fairly positive theyre likely to be informed a great deal of new stuff here than anyone http://www.georgiagbea.org/

    ReplyDelete
  11. I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally. Im fairly positive theyre likely to be informed a great deal of new stuff here than anyone najlepszy forex broker

    ReplyDelete
  12. I’m able to bookmark your site and show the kids check out up here generally. Im fairly positive theyre likely to be informed a great deal of new stuff here than anyone edusson.com scam

    ReplyDelete
  13. Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. Reservations.com

    ReplyDelete
  14. AromaSuperStore Cheap Aromatherapy online. We have a large selection of products to choose from. We have daily coupons and reviews of our products AromaSuperStore daily deals

    ReplyDelete
  15. This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine. write my argumentative essay

    ReplyDelete
  16. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me click here now

    ReplyDelete
  17. Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists grading essays

    ReplyDelete
  18. Keep up the good work, I read few posts on this web site and I conceive that your blog is very interesting and has sets of fantastic information essaydoc coupon

    ReplyDelete
  19. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post. speedy paper reviews

    ReplyDelete
  20. Thank you again for all the knowledge you distribute, Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting your site since I always come across interesting articles like this one.Great Job, I greatly appreciate that do Keep sharing! دانلود اینستاگرام

    ReplyDelete
  21. Thank you again for all the knowledge you distribute, Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting your site since I always come across interesting articles like this one.Great Job, I greatly appreciate that do Keep sharing! do my paper

    ReplyDelete
  22. This is a great inspiring article. I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. binary signals reviews

    ReplyDelete
  23. Thank you again for all the knowledge you distribute, Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting your site since I always come across interesting articles like this one.Great Job, I greatly appreciate that do Keep sharing! صيانة زانوسي

    ReplyDelete
  24. I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your goal. سانترال

    ReplyDelete
  25. Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. death by captcha

    ReplyDelete
  26. This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. here download

    ReplyDelete
  27. Thank you again for all the knowledge you distribute, Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting your site since I always come across interesting articles like this one.Great Job, I greatly appreciate that do Keep sharing! Dubai Vacation Reviews

    ReplyDelete
  28. This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. review pipsar

    ReplyDelete
  29. I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. click here

    ReplyDelete
  30. Thanks for sharing nice information with us. i like your post and all you share with us is up to date and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. women's fashion

    ReplyDelete
  31. Thanks for sharing nice information with us. i like your post and all you share with us is up to date and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. وی اس تی

    ReplyDelete
  32. The information you have posted is very useful. The sites you have referred is good. Thanks for sharing...hcg injections

    ReplyDelete
  33. Thanks for sharing nice information with us. i like your post and all you share with us is up to date and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. Essay Have can cope with any type of paper

    ReplyDelete
  34. The information you have posted is very useful. The sites you have referred is good. Thanks for sharing...Quality Knife

    ReplyDelete
  35. You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you. medical bracelets

    ReplyDelete
  36. This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. عکاسی تبلیغاتی

    ReplyDelete
  37. Thanks for sharing nice information with us. I like your post and all you share with us is up to date and quite informative, I would like to bookmark the page so I can come here again to read you, as you have done a wonderful job. hotforex.com

    ReplyDelete
  38. The information you have posted is very useful. The sites you have referred is good. Thanks for sharing...best kitchen knives set

    ReplyDelete
  39. This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. clash royale android

    ReplyDelete
  40. Thanks for sharing nice information with us. I like your post and all you share with us is up to date and quite informative, I would like to bookmark the page so I can come here again to read you, as you have done a wonderful job. دانلود آهنگ جدید

    ReplyDelete
  41. I really impressed after read this because of some quality work and informative thoughts . I just wanna say thanks for the writer and wish you all the best for coming! تجاری سازی فناوری

    ReplyDelete
  42. This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. lindas escorts en bogota

    ReplyDelete
  43. Thanks for taking the time to discuss this. I feel strongly that love and read more on this topic. If possible. such as gain knowledge. would you mind updating your blog with additional information? It is very useful for me. top 5 homework apps

    ReplyDelete
  44. I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. tattoo images of scrolls

    ReplyDelete
  45. I’m able to bookmark your site and show the kids check out up here generally. I’m fairly positive theye likely to be informed a great deal of new stuff here than anyone Friendship Messages Whatsapp

    ReplyDelete
  46. Thanks for taking the time to discuss this. I feel strongly that love and read more on this topic. If possible. such as gain knowledge. would you mind updating your blog with additional information? It is very useful for me. discount code sammydress

    ReplyDelete
  47. Thanks for sharing nice information with us. I like your post and all you share with us is up to date and quite informative, I would like to bookmark the page so I can come here again to read you, as you have done a wonderful job. https://miappy.com/gardenscapes-hack/

    ReplyDelete
  48. This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. distributor cctv murah

    ReplyDelete
  49. This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. freeapkdownloader.info

    ReplyDelete
  50. This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine. Casio Sports Unisex Resin Chronograph Watch W-214h-4avef

    ReplyDelete
  51. This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. Forex Technical Analysis

    ReplyDelete
  52. Thanks for sharing nice information with us. I like your post and all you share with us is up to date and quite informative, i would like to bookmark the page so I can come here again to read you, as you have done a wonderful job. best forex trading platform

    ReplyDelete
  53. Thanks for sharing nice information with us. I like your post and all you share with us is up to date and quite informative, I would like to bookmark the page so I can come here again to read you, as you have done a wonderful job. سبک زندگی

    ReplyDelete
  54. This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. download imo

    ReplyDelete
  55. Link building is the most important because, once search engines have crawled pages on the web, they can extract the content of those pages and add it to their indexes. In this way, they can decide if they feel a page is of sufficient quality to be ranked well for relevant keywords. When they are deciding this, the search engines do not just look at the content of the page. Generally speaking, the more high-quality websites that link to you, the more likely you are to rank well in search results. High Quality Backlinks

    ReplyDelete
  56. This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. Mod Android Games

    ReplyDelete
  57. This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. hcg

    ReplyDelete
  58. Thanks for taking the time to discuss this. I feel strongly that love and read more on this topic. If possible. such as gain knowledge. would you mind updating your blog with additional information? It is very useful for me. appy birthday big sister

    ReplyDelete
  59. Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info High Trust Flow Dofollow Backlinks

    ReplyDelete
  60. It was really a great narration, my cousin suggested it to me thank you for everything
    Edirne Vestel Servisi

    ReplyDelete
  61. I agree with you. This post is truly inspiring. I like your post and everything you share with us is current and very informative, I want to bookmark the page so I can return here from you that you have done a fantastic job Dofollow Blog Comments

    ReplyDelete