Ipad development saves images to files

Source: Internet
Author: User

 

Images downloaded from the Internet, if you want to achieve permanent storage, need to be saved to files or databases, the current file io is the fastest, haha

 

The core code is as follows:

 

-(NSString *) findUniqueSavePath

 

{

 

Int I = 1;

 

NSString * path;

 

Do {

 

// This loop knows how to save a new image ......

 

Path = [NSString stringWithFormat: @ "% @/Documents/IMAGE _ % 04d. PNG", NSHomeDirectory (), I ++];

 

} While ([[NSFileManager defaultManager] fileExistsAtPath: path]);

 

 

Return path;

 

}

 

 

-(Void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary *) info

 

{

 

UIImage * image = [info objectForKey: @ "UIImagePickerControllerOriginalImage"];

 

[Self dismissModalViewControllerAnimated: YES];

 

[Picker release];

 

 

// Png and jpeg modes for file writing

 

// [UIImageJPEGRepresentation (image, 1.0f) writeToFile: [self findUniqueSavePath] atomically: YES];

 

[UIImagePNGRepresentation (image) writeToFile: [self findUniqueSavePath] atomically: YES];

 

 

// Set the current window to Beijing

 

SETIMAGE (image );

 

 

// Display the list of currently written files

 

CFShow ([[NSFileManager defaultManager] directoryContentsAtPath: [NSHomeDirectory () stringByAppendingString: @ "/Documents"]);

 

}

 

----------------------

 

For how to read images in a file, see my previous blog.

 

Author sdhjob

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.