.h File:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
IBOutlet UIButton *btn;
IBOutlet UIImageView *imageView;
}
@property(nonatomic, retain) IBOutlet UIImageView *imageView;
@end
.m File:
- (void)picturePicker:(UIImagePickerControllerSourceType)theSource {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = theSource;
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (IBAction) takePicture:(id)sender {
if([UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceRear] || [UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront])
{
UIImagePickerControllerSourceType source = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable:source]) {
[self picturePicker:source];
}
}
else
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Message" message:@"There is no Camera on your device" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
imageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
}
No comments:
Post a Comment