3
可能是這個問題太簡單了,或者我不知道它會多麼容易。如何防止再次從照相機保存圖片
我有一個操作表,允許用戶選擇如何拍攝照片或從相機中選擇。
該應用程序將保存用戶拍攝的照片,無論是從相機膠捲中選擇或從相機拍攝。我錯過了什麼嗎?
感謝您閱讀我的問題。
#pragma mark - photo select
-(IBAction)showCameraAction:(id)sender
{
if(![UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@""
delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
otherButtonTitles:@"Choose Photo From Library", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
actionSheet.tag =1;
[actionSheet showInView:[self.view superview]];
}
else
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@""
delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
otherButtonTitles:@"Take Photo With Camera", @"Choose Photo From Library", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
actionSheet.tag =1;
[actionSheet showInView:[self.view superview]];
}
}
- (void)getPhotoFromSource:(UIImagePickerControllerSourceType)sourceType;
{
//NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
if ([UIImagePickerController isSourceTypeAvailable:sourceType])
{
//NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
//picker.mediaTypes = mediaTypes;
picker.delegate = self;
//picker.allowsEditing = YES;
picker.sourceType = sourceType;
[self presentModalViewController:picker animated:YES];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing media" message:@"Device doesn't support media source" delegate:nil cancelButtonTitle:@"Drat" otherButtonTitles:nil, nil];
[alert show];
}
}
#pragma mark UIImagePickerController delegate methods
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.lastChosenMediaType = [info objectForKey:UIImagePickerControllerOriginalImage];
imageFrame=fImageView.frame;
//UIImage *chosenImage = [info objectForKey:UIImagePickerControllerEditedImage];
UIImage *orginalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *shrunkenImage = shrinkImage(orginalImage,imageFrame.size);
self.fImage = shrunkenImage;
fImageView.image = frogImage;
//answer fix, to prevent saving picture from cameraroll again.
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
{
UIImageWriteToSavedPhotosAlbum(orginalImage, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
//NSString *message;
//NSString *title;
// if (!error) {
// title = NSLocalizedString(@"SaveSuccessTitle", @"");
// message = NSLocalizedString(@"SaveSuccessMessage", @"");
// } else {
// title = NSLocalizedString(@"SaveFailedTitle", @"");
// message = [error description];
// }
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
// message:message
// delegate:nil
// cancelButtonTitle:NSLocalizedString(@"ButtonOK", @"")
// otherButtonTitles:nil];
// [alert show];
}
如果你不給編輯選項,你必須使用UIImagePickerControllerOriginalImage代替UIImagePickerControllerEditedImage – 2012-01-16 07:22:42
找到了答案 如果(picker.sourceType == UIImagePickerControllerSourceTypeCamera) { UIImageWriteToSavedPhotosAlbum(orginalImage,自我,@selector(imageSavedToPhotosAlbum:didFinishSavingWithError :contextInfo :),nil); } – Desmond 2012-01-25 05:12:31