2013-07-17 85 views
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,並與許多視圖控制器混淆,但我真的很喜歡這個工作,我無法找到任何關於此主題的資源。謝謝。

+0

你希望用戶選擇一個類別保存到? – user523234

+0

是的!用戶在應用程序內拍照並保存,以便用戶可以在應用程序中看到圖片而不在照片庫中。 – user2590480

回答

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

+0

對不起,我不希望它保存到相冊中,我希望用戶輸入數據,然後將其保存在應用程序中。並感謝網站。 – user2590480

+0

你的意思是在應用程序內?你要將這些圖像存儲在本地數據庫中?或網絡服務器? – Ajay

+0

所以它的一個應用程序,用戶在應用程序側拍攝照片,然後他將照片分類存儲(意味着他只能在應用程序中訪問照片)。在應用程序中保存.. – user2590480