用数据保存图片

时间:2013-07-17 08:35:23

标签: ios image save

我知道如何保存图片,这是迄今为止的代码。此代码显示用户点按一个按钮即可拍照。

-(IBAction)TakePhoto {
picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:nil];
}

- (IBAction)ChooseExisting {
picker2 = [[UIImagePickerController alloc]init];
picker2.delegate = self;
[picker2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker2 animated:YES completion:nil];

}


- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageview setImage:image];

//Save Your Image ======
UIImage *yourImage  = imageview.image;//imageView.image;
NSString *docDirPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *filePath = [docDirPath stringByAppendingPathComponent:@"myImageFile.png"];
[UIImagePNGRepresentation(yourImage) writeToFile:filePath atomically:YES];
[self dismissViewControllerAnimated:YES completion:nil];

}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:NULL];

}

但是,我想将保存的图片分类为6个类别或类型,用户必须使用段视图控件进行分类。这可能吗?我是ios编程和xcode中的objective-c的新手,并且与许多视图控制器混淆但是我真的很喜欢这个工作,我找不到关于这个主题的任何资源。感谢。

1 个答案:

答案 0 :(得分:0)

以下是使用ALAssetsLibrary将图像保存到特定相册的精彩演示:

http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/

我希望它会帮助你...

您可以使用以下代码创建不同的库:

-(void)createDirectory:(NSString *)directoryName atFilePath:(NSString *)filePath
{
    NSString *filePathAndDirectory = [filePath stringByAppendingPathComponent:directoryName];
    NSError *error;

    if (![[NSFileManager defaultManager] createDirectoryAtPath:filePathAndDirectory
                                   withIntermediateDirectories:NO
                                                    attributes:nil
                                                         error:&error])
    {
        NSLog(@"Create directory error: %@", error);
    }
} 

通过各自的路径获取图片!!!

有关详细信息,请参阅:http://kmithi.blogspot.in/2012/08/ios-application-directory-structure.html