Save a picture to a sandbox or album

Source: Internet
Author: User

Save the picture to a sandbox or album:
1. Save to album:

-(void) Saveimagetoalbum: (UIButton *) sender{
Save a picture in an album
Uiimagewritetosavedphotosalbum (Self.image, Self, @selector (image:didFinishSavingWithError:contextInfo:), nil);
}

2. Save to Sandbox

-(void) Saveimagetosandbox: (UIButton *) sender{

Save a picture to a sandbox
Save File to Sandbox
Get the documents directory path in the sandbox
NSString *documents = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, Nsuserdomainmask, YES) firstObject ];

NSLog (@ "%@", documents);

NSString *documents = [Nshomedirectory () stringbyappendingpathcomponent:@ "/documents"];

NSLog (@ "%@", documents);
Stitching file Absolute Path
NSString *path = [documents StringByAppendingPathComponent:self.fileName];

Save
[Self.results Writetofile:path Atomically:yes];
}

This method is used regardless of whether the save succeeds or fails

-(void) Image: (UIImage *) image didfinishsavingwitherror: (nserror *) error ContextInfo: (void *) contextinfo{

if (Error! = nil) {
Uialertview *fail = [[Uialertview alloc]initwithtitle:@ ' Prompt ' message:@ ' save failed ' delegate:self cancelbuttontitle:@ ' OK ' Otherbuttontitles:nil, nil];
[Fail show];
NSLog (@ "%@", error);
}
else{
Uialertview *alert = [[Uialertview alloc]initwithtitle:nil message:@ "Save succeeded" delegate:self cancelbuttontitle:@ "OK" Otherbuttontitles:nil, nil];

[Alert show];
[Self.view Addsubview:alert];
}
}

Save a picture to a sandbox or album

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.