0

私は画像を保存する方法を知っており、これが今までのコードです。このコードは、ユーザーがボタンをタップして写真を撮ることができることを示しています。

-(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が非常に新しく、多くのビューコントローラーと混同していますが、これが機能するのが本当に好きで、このトピックに関するリソースが見つかりません. ありがとう。

4

1 に答える 1

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を参照してください。

于 2013-07-17T09:26:08.367 に答える