NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:NO completion:nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo){
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
//save to document directory
NSData *pngData = UIImagePNGRepresentation([self imageWithImage:image scaledToSize:CGSizeMake(image.size.width/5, image.size.height/5)]);
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image_test.png"]; //Add the file name
[pngData writeToFile:filePath atomically:YES]; //Write the file
}
这是您需要保存到照片的所有内容。如果您希望将其保存为 uiimage,请查看以下内容:
if ([NSData dataWithContentsOfFile:[self documentsPathForFileName:@"image_test.png"]]) {
NSData* pngData = [NSData dataWithContentsOfFile:[self documentsPathForFileName:@"image_test.png"]];
UIImage* image = [UIImage imageWithData:pngData];
UIImageView* imageView = [[UIImageView alloc] initWithImage:image];
[imageView setFrame:CGRectMake(0.0, 0.0, imageView.image.size.width, imageView.image.size.height)];
[imageView setCenter:self.view.center];
[self.view addSubview:imageView];
}