2010-08-05 107 views
0

我現在正在採用位於Resources文件夾中的1個字符串中的硬編碼圖像,然後通過 上傳和下載處理該字符串。從相機捕獲圖像並將其保存爲字符串

我的第一項任務仍然存在。 我想通過攝像頭捕捉圖像,並希望保存到Resources文件夾中,並且還想將其賦予1個字符串。

回答

0

如果你想不想找個顯示圖像,你可以使用:

-(void)chooseImageFromCamera { 
    if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) return; 

    UIImagePickerController* picker = [[UIImagePickerController alloc] init]; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    picker.delegate = self; 
    picker.allowsEditing = YES; 
    picker.wantsFullScreenLayout = YES; 

    [currentItem retain]; 
    [self presentModalViewController:picker animated:YES]; 
} 

#pragma mark Image Picker Delegates 

-(void)imagePickerController:(UIImagePickerController *)picker 
     didFinishPickingImage:(UIImage *)image 
       editingInfo:(NSDictionary *)editingInfo { 

    NSData *chosenImage = UIImageJPEGRepresentation(image, 1.0); 

     /* change this to the path of a plist file */ 
    NSString *current = [NSString stringWithFormat:@"PlistFile.plist"]; 
    NSMutableDictionary* plistDict = [[[NSMutableDictionary alloc] initWithContentsOfFile:current] autorelease]; 

    // Do something with the image here. 
    [plistDict setObject:chosenImage forKey:@"Photo"]; 
    [plistDict writeToFile:current atomically:YES]; 
    [self dismissModalViewControllerAnimated:YES]; 
} 

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 
    [[picker parentViewController] dismissModalViewControllerAnimated:YES]; 
} 
相關問題