allowsediting move and scale doesn't work - ios

This is my code for.m
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
for.h
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)takePhoto: (UIButton *)sender;
However when I try to move to scale it bounces back to the center so i can't even crop anything.

Related

How to save the image captured using Camera and save in another ViewController?

How to save the image captured using Camera and save in another ViewController ?
I am making a Photo Gallery App. But i dont know how to save the Captured image and show it in collection view in another viewcontroller. Currently i am using UIImagePickerController to access iphone camera and library .Can anyone help me to do that.
Here is my code.
Thanks in advance
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewDidLoad {
[super viewDidLoad];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Device has no camera"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[myAlertView show];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Try This
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
// Save image
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
[picker release];
}
you can achieve it by adding NSNotificationcenter.
Class A - Where you select the image from camera
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
[[NSNotificationCenter defaultCenter] postNotificationName: #"GotNewImage" object: chosenImage];
}
Class B - Where you want to pass image after selection and show on collection view. Add Nsnotificationcenter for this class in Viewdidload
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(GotNewImage:) name:#"GotNewImage" object:nil];
//To get the image on Class B
-(void)GotNewImage:(NSNotification*)notification
{
UIImage * newImage = (UIImage*) notification.object;
//Now do whatever you want to do with your image...
//Add in collection view and reload the collection view
}

How to pass image from one page to another in ios

i want to pass image from one page to another by selecting image from gallery or using camera.whe user click on display button image will be tranfered to next page
i have tried this. but not working in .m file
#interface ImagePicker () <UIImagePickerControllerDelegate>
{
IBOutlet UIImageView *imageview;
UIImageView *fordisplay;
}
#end
#implementation ImagePicker
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)clickOnDate:(id)sender
{
datePicker *date=[[datePicker alloc]initWithNibName:#"datePicker" bundle:nil];
[self.navigationController pushViewController:date animated:YES];
}
-(IBAction)selectPhoto:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
-(IBAction)takePhoto:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
DisplayImage *obj_display1=[[DisplayImage alloc]initWithNibName:#"DisplayImage" bundle:nil];
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
//self.imageview.image = chosenImage;
imageview.image=chosenImage;
obj_display1.imageDisplayy=chosenImage;**
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
-(IBAction)display:(id)sender
{
DisplayImage *obj_display=[[DisplayImage alloc]initWithNibName:#"DisplayImage" bundle:nil];
[self.navigationController pushViewController:obj_display animated:YES];
}
and in next page where want to display image
.h file
#property(nonatomic,strong) UIImageView *imageDisplayy;
.m file
#synthesize imageDisplayy;
- (void)viewDidLoad {
[super viewDidLoad];
obj_imageview.image=imageDisplayy;
}
You are creating an instance of DisplayImage in your this method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
While performing navigation you are creating another new instance which doesn't have imageDisplayy property set for it.
-(IBAction)display:(id)sender
{
DisplayImage *obj_display=[[DisplayImage alloc]initWithNibName:#"DisplayImage" bundle:nil];
[self.navigationController pushViewController:obj_display animated:YES];
}
One solution for this problem is make DisplayImage *obj_display1 as property in your ImagePicker.
#property(nonatomic,strong) DisplayImage *obj_display1;
Instantiate it in viewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.obj_display1=[[DisplayImage alloc]initWithNibName:#"DisplayImage" bundle:nil];
}
update code in this method as
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
//self.imageview.image = chosenImage;
imageview.image=chosenImage;
self.obj_display1.imageDisplayy=chosenImage;**
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Then perform navigation
-(IBAction)display:(id)sender
{
[self.navigationController pushViewController:self.obj_display1 animated:YES];
}
Your are directly passing image to imagview.Instead of that pass image from one view controller to anorther.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
DisplayImage *obj_display1=[[DisplayImage alloc]initWithNibName:#"DisplayImage" bundle:nil];
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
//self.imageview.image = chosenImage;
imageview.image=chosenImage;
obj_display1.imageDisplayy=chosenImage;**
[picker dismissViewControllerAnimated:YES completion:NULL];
}
next page where want to display image
.h file
#property(nonatomic,strong) UIImage *imageDisplayy;
.m file
#synthesize imageDisplayy;
- (void)viewDidLoad {
[super viewDidLoad];
obj_imageview.image=imageDisplayy;
}
try this :
//In .h file
// change your property to UIImage instead of imageview
#property(nonatomic,strong) UIImage *imageDisplayy;

ios UIImagePickerController not working

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init] ;
[imagePicker setAllowsEditing:YES] ;
[imagePicker setDelegate:self] ;
[imagePicker setMediaTypes:[NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil]] ;
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary] ;
[self presentViewController:imagePicker animated:YES completion:nil] ;
Step 1: Add Delegate
#interface APPViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
Step 2: Initialize UIImagePicker on click button Action
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
Step 3:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Step 4: Dismiss controller
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Note: Post your Question with detail description
You are using UIImagePickerController as a variable not as an attribute or property, it means that it will be released at the end of your function. Set your UIImagePickerController as an attribute or property and then the delegate will work.
If you are using a UIPopoverPresentationController, make sure you dismiss the popover before presenting the imagePicker. Otherwise, it will not be shown.

ImagePickerController for iOS

I am trying to select a picture from the device's photo library.
This is my code so far. I am following a tutorial and that should work, but I am getting an error :
"Use of undeclared identifier info", on the second method, line 3.
What am I doing wrong?
- (IBAction)selectPicturePressed:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo
{
UIImage *chosenImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
self.imgToUpload.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Change info to editInfo will resolve it.

How to save the selected image in UIImagePicker controller?

I can take a photo and it shows in imageviewn but as soon as I leave detailviewn and go to back to detailviewn its disappear. How should the image always be saved?
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Check your IBOutlet Connection in xib file and You have to save the image taken in documents directory of your application , unless you cannot view the selected image

Resources