English 中文(简体)
如何防止照相机照相机再次播放照片
原标题:how to prevent saving picture from camera roll again

也许这个问题太容易,或者我不知道这个问题会多么容易。

I have an actionsheet to allow the user to choose how if they want to take a photo or select from camera.

该照片将节省被照相带的用户,而不论用户是从摄像机中挑选的还是从摄像机中提取的。 我失踪了吗?

感谢阅读我的问题。

#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];
}
最佳回答

引证该法典。 它从我方适当开展工作。

- (IBAction) uploadPhoto:(id)sender
{
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@""
                                                                 delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
                                                        otherButtonTitles:@"Use Photo from Library", @"Take Photo with Camera", nil];
        actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
        actionSheetAction = ActionSheetToSelectTypeOfSource;
        [actionSheet showInView:self.view];
        [actionSheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    UIImagePickerControllerSourceType sourceType;
                if (buttonIndex == 0) {
                    sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                } else if(buttonIndex == 1) {
                    sourceType = UIImagePickerControllerSourceTypeCamera;
                }else {
                    // Cancel
                    break;
                }
                if([UIImagePickerController isSourceTypeAvailable:sourceType]) {
                    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                    picker.sourceType = sourceType;
                    picker.delegate = self;
                    if (sourceType == UIImagePickerControllerSourceTypeCamera) {
                        picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
                    }
                    picker.allowsImageEditing = NO;
                    [self presentModalViewController:picker animated:YES];
                    [picker release];
                }

}

#pragma mark -
#pragma mark UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES);
 NSString *docDirectory = [paths objectAtIndex:0];
 NSString *imgPath = [documentsDirectory stringByAppendingPathComponent:[NSString  stringWithFormat:@"image1.png"]];

//COnvert it to NSData before saving and then save it
    NSData *imgData = UIImagePNGRepresentation(image);
    [imgData writeToFile:imgPath atomically:YES];
   [self dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [self dismissModalViewControllerAnimated:YES];
}
问题回答

页: 1 代表

检查这一职能

  • (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{}
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; 
if ([mediaType isEqualToString:@"public.image"]){
        UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];

}

现在使用的是UIImage

保存这一形象 你们必须指明一条道路

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"photo.png"]];

//COnvert it to NSData before saving and then save it
    NSData *webData = UIImagePNGRepresentation(editedImage);
    [webData writeToFile:imagePath atomically:YES];




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签