=> Confirm Protocol Of UIimagePickerControllerDelegate:
@interface ViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *imgView;
@end
------------------------------
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
==> Here UIimage With NSData Used NSUrl:
UIImage *img =[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjN0jOr9aVt9g1OIB-lfSO2lBBPvzO_I06eJ_i2x6y1TP1kPqM1t7ND_krBXO2600wwH38jrmaMpnISR2WAk6CMblXQOKsjgCqxoXC-YjG4EJIop6vN_omvttVxvrAE2gANyXv_iYA51Rk/s1600/1.png"]]];
_imgView.image = img;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
=> To Take Photo Action From Camera:
- (IBAction)btnTakePhotoAction:(id)sender {
[self takePhotoMode:YES];
}
=> This Method Used For Load From GelleryView Action In UIImagePicker:
- (IBAction)btnLoadFromGallaryAction:(id)sender {
[self takePhotoMode:NO];
}
=> To Take Photo Mode And Check Source Type in ImagePIcker:
-(void)takePhotoMode:(BOOL)isFromCamera{
if (isFromCamera && ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Device has no camera"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[myAlertView show];
return;
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = isFromCamera?UIImagePickerControllerSourceTypeCamera:UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
==> Used For UIImagePickerDelegate Method And Action:-
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
UIImage *origionalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
self.imgView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
[self saveImageToDouments:chosenImage];
}
==> Used For Save Image TO Document In UiImagePickerController:-
-(void)saveImageToDouments:(UIImage*)image{
NSString *aStrDoc =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
NSString *fullPath = [aStrDoc stringByAppendingPathComponent:@"sample.jpg"];
NSData *imgData = UIImageJPEGRepresentation(image, 0.8);
[imgData writeToFile:fullPath atomically:YES];
}
=> Use Action For Save Image In Gallery Using UIIMagePIckerController:-
-(void)saveImageToGallary:(UIImage*)image{
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
@end
@interface ViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *imgView;
@end
------------------------------
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
==> Here UIimage With NSData Used NSUrl:
UIImage *img =[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjN0jOr9aVt9g1OIB-lfSO2lBBPvzO_I06eJ_i2x6y1TP1kPqM1t7ND_krBXO2600wwH38jrmaMpnISR2WAk6CMblXQOKsjgCqxoXC-YjG4EJIop6vN_omvttVxvrAE2gANyXv_iYA51Rk/s1600/1.png"]]];
_imgView.image = img;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
=> To Take Photo Action From Camera:
- (IBAction)btnTakePhotoAction:(id)sender {
[self takePhotoMode:YES];
}
=> This Method Used For Load From GelleryView Action In UIImagePicker:
- (IBAction)btnLoadFromGallaryAction:(id)sender {
[self takePhotoMode:NO];
}
=> To Take Photo Mode And Check Source Type in ImagePIcker:
-(void)takePhotoMode:(BOOL)isFromCamera{
if (isFromCamera && ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Device has no camera"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[myAlertView show];
return;
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = isFromCamera?UIImagePickerControllerSourceTypeCamera:UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
==> Used For UIImagePickerDelegate Method And Action:-
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
UIImage *origionalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
self.imgView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
[self saveImageToDouments:chosenImage];
}
==> Used For Save Image TO Document In UiImagePickerController:-
-(void)saveImageToDouments:(UIImage*)image{
NSString *aStrDoc =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
NSString *fullPath = [aStrDoc stringByAppendingPathComponent:@"sample.jpg"];
NSData *imgData = UIImageJPEGRepresentation(image, 0.8);
[imgData writeToFile:fullPath atomically:YES];
}
=> Use Action For Save Image In Gallery Using UIIMagePIckerController:-
-(void)saveImageToGallary:(UIImage*)image{
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
@end