ios - Data passing of photo taken in App -


i used code

  -(ibaction)takephoto { picker = [[uiimagepickercontroller alloc]init]; picker.delegate = self; [picker setsourcetype:uiimagepickercontrollersourcetypecamera]; [self presentviewcontroller:picker animated:yes completion:nil]; [self performseguewithidentifier:@"cropimage" sender:sender]; }   - (void) imagepickercontroller:(uiimagepickercontroller *)picker  didfinishpickingmediawithinfo:(nsdictionary *)info {  //obtaining saving path nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *imagepath = [documentsdirectory stringbyappendingpathcomponent:@"latest_photo.png"];  //extracting image picker , saving nsstring *mediatype = [info objectforkey:uiimagepickercontrollermediatype]; if ([mediatype isequaltostring:@"public.image"]){     uiimage *editedimage = [info objectforkey:uiimagepickercontrollereditedimage];     nsdata *webdata = uiimagepngrepresentation(editedimage);     [webdata writetofile:imagepath atomically:yes]; } } - (void)imagepickercontrollerdidcancel  :(uiimagepickercontroller *)picker { [self dismissviewcontrolleranimated:yes completion:null];  }   - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if([segue.identifier isequaltostring:@"cropimage"]) {     cropimageviewcontroller *cropimageviewcontroller = segue.destinationviewcontroller;     cropimageviewcontroller.theimage = yourimage;     // similar [segue.destinationviewcontroller settheimage:yourimage];     }  } 

i have problem here using storyboard. have multiple view controllers in storyboard. have camera button (which user can take photo in app) on first view controller. want pass data of photo user took in first view controller view controller automatically user can crop , save "directory or something"(did not decide yet).

update having 4 errors saying http://tinypic.com/view.php?pic=15q6y3b&s=5 click image bigger

actually, don't have pass photo directly next view since had saved it. can read image same file in target view controller. (this method better if view controllers not close 1 another.)

+ (uiimage *)readimagefromfile:(nsstring *)name {     nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);     nsstring *documentsdirectory = [paths objectatindex:0];     nsstring *imagepath = [documentsdirectory stringbyappendingpathcomponent:@"latest_photo.png"];      nsdata *imagedata = [nsdata datawithcontentsoffile:imagepath];     return [uiimage imagewithdata:imagedata]; } 

updated: can pass photo using property though.

in target view controller (i name cropimageviewcontroller), in .h,

@property (nonatomic, retain) uiimage *theimage; 

in "getphoto" view controller, on top of page,

#import "cropimageviewcontroller.h" 

in imagepickercontroller,

- (void) imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info  {     ...     // line should     [self performseguewithidentifier:@"cropimage" sender:self]; } 

in prepareforsegue method:

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     if([segue.identifier isequaltostring:@"cropimage"])     {         cropimageviewcontroller *cropimageviewcontroller = segue.destinationviewcontroller;         cropimageviewcontroller.theimage = yourimage;         // similar [segue.destinationviewcontroller settheimage:yourimage];     } } 

make sure set name, e.g. "cropimage", segue identifier in storyboard.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -