iOS Dev > Learning-Save photo to System album (Photo Album)

Source: Internet
Author: User

Save photos to System albums This feature is available in many social apps, so let's talk about how to save images to the system album (Photo Album) today.

Create Uiimageview

Created to UIImageView show the photo, we are going to save it UIImage to the system album (Photo Album):

#define SCREEN [UIScreen mainScreen].bounds.sizeself.image = [UIImage imageNamed:@"iOSDevTip"];UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN.width - 300) / 2, 70, 300, 150)];imageView.image = self.image;[self.view addSubview:imageView];
Create UIButton

To create UIButton and bind an actionClick: event:

 UIButton *button = [[UIButton alloc] init];button.frame = CGRectMake( 100, 300, SCREEN.width - 200, 40);[button addTarget:self action:@selector(actionClick:) forControlEvents:UIControlEventTouchUpInside];[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];[button setBackgroundColor:[UIColor orangeColor]];[button setTitle:@"SavePhoto" forState:UIControlStateNormal];[self.view addSubview:button];- (void)actionClick:(UIButton *)button{}
Save photo to System album (Photo Album)

Called in the actionClick: method:

UIImageWriteToSavedPhotosAlbum(self.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);

This time, we want to know if the save is successful, so we need to devise a method of ruin

// 指定回调方法- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{    if(!error){        NSLog(@"save success");    }else{        NSLog(@"save failed");    }}

In this method, we know whether the photo was saved successfully. Then, refresh the UI thread as needed. Demo Address: Https://github.com/worldligang/iOSStrongDemo (or click "Read the original" There is a demo link address). The next article will tell you how to create your own albums and save your photos.

iOS Dev > Learning-Save photo to System album (Photo Album)

Related Article

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.