[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

xcode how to save an image

Posted on 2010-09-20
4
Medium Priority
?
2,320 Views
Last Modified: 2012-05-10
how do you save an image after you take a picture? In my app i'm using an UIImagePickerController that takes the picture but i don't know how to save the image.
0
Comment
Question by:BTMExpert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 2000 total points
ID: 33722320
If you need to save it in the album: UIImageWriteToSavedPhotosAlbum
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIKitFunctionReference/Reference/reference.html

Another way:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/40279-save-uiimagepickercontroller-user-default.html

The simplest case: in the didFinish you can save the image:
UIImageWriteToSavedPhotosAlbum(image, nil,nil,nil);

But this way will look better:
UIImageWriteToSavedPhotosAlbum(reconstructedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
and [image autorelease]; in the callback.
As it's shown here:
http://stackoverflow.com/questions/3017681/uiimagewritetosavedphotosalbum-working-sometimes

Another way.
The first step is always to convert UIImage to NSData:
NSData *ImageData = UIImageJPEGRepresentation(img, 0.9);

Now, when it's already NSData, we can save it. In that thread people saved in the preferences:
[[NSUserDefaults standardUserDefaults] setObject:ImageData forKey:@"image"];
      
More info about the question:
http://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more

0
 

Author Comment

by:BTMExpert
ID: 33724869
that helped so much thank you.  One small problem now.  everytime i click the button to save my image, it saves which is great but when i try to do anything else after that, the app crashes.

- (IBAction)saveImage {
      UIImage *image = imageView.image;      

      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Image" message:@"Image" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
      [alert show];
      [alert release];
      
      UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
}

- (void)image:(UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo {
      NSLog(@"SAVE IMAGE COMPLETE");
      if(error != nil) {
            NSLog(@"ERROR SAVING:%@",[error localizedDescription]);
      }
      [image autorelease];
}
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33724898
Maybe, because of that line:  [image autorelease];

try to cmment it. If it does not help, comment the alert (all lthree lines about the alert).
 
0
 

Author Comment

by:BTMExpert
ID: 33724911
i took the [image release]; out and it works now. Thanks a lot!!!!!!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question