在 iPhone 中捕捉视频和图像

发布于 2024-11-09 15:31:08 字数 232 浏览 0 评论 0原文

我正在使用 ImagePickerController 进行视频捕获。我还需要将捕获视频保存为图像。

所以我选择了 AVCaptureSession 来捕获图像。我无法运行 AVCaptureSession 以及 ImagePickerController。所以我需要将 ImagePickerController 作为 AVCaptureSession 的输入。

但我不知道该怎么做。请帮助我..并建议我正确的方法。

I am using ImagePickerController for Video Capturing. I need to save the capturing video as image also.

So I selected AVCaptureSession for capturing Images. I'm not able to run AVCaptureSession as well as ImagePickerController. So I need to give the ImagePickerController as input to the AVCaptureSession.

But I don't know how to do that. Please Help me.. and suggest me for the right way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

与往事干杯 2024-11-16 15:31:08

我遇到了同样的问题..我确实对图像和视频进行了处理,并使用下面的代码进行图像捕获:

- (void) snapImage: (id) sendern
{
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    ipc.sourceType =  UIImagePickerControllerSourceTypeCamera;
    ipc.delegate = self;
    ipc.allowsImageEditing = YES;
    [self presentModalViewController:ipc animated:YES]; 

}

对于视频录制,我使用了下面的代码:

- (void) recordVideo: (id) sender
{
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    ipc.sourceType =  UIImagePickerControllerSourceTypeCamera;
    ipc.delegate = self;
    ipc.allowsEditing = YES;
    ipc.videoQuality = UIImagePickerControllerQualityTypeMedium;
    ipc.videoMaximumDuration = 30.0f; // 30 seconds
    ipc.mediaTypes = [NSArray arrayWithObject:@"public.movie"];
    // ipc.mediaTypes = [NSArray arrayWithObjects:@"public.movie", @"public.image", nil];
    [self presentModalViewController:ipc animated:YES]; 
}

希望会对您有所帮助。

I was having same issue.. I did work on image and video and used below code for image capturing:

- (void) snapImage: (id) sendern
{
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    ipc.sourceType =  UIImagePickerControllerSourceTypeCamera;
    ipc.delegate = self;
    ipc.allowsImageEditing = YES;
    [self presentModalViewController:ipc animated:YES]; 

}

And for video recording i used below code:

- (void) recordVideo: (id) sender
{
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    ipc.sourceType =  UIImagePickerControllerSourceTypeCamera;
    ipc.delegate = self;
    ipc.allowsEditing = YES;
    ipc.videoQuality = UIImagePickerControllerQualityTypeMedium;
    ipc.videoMaximumDuration = 30.0f; // 30 seconds
    ipc.mediaTypes = [NSArray arrayWithObject:@"public.movie"];
    // ipc.mediaTypes = [NSArray arrayWithObjects:@"public.movie", @"public.image", nil];
    [self presentModalViewController:ipc animated:YES]; 
}

Hope will help you both code snippets.

我是男神闪亮亮 2024-11-16 15:31:08
    - (IBAction) useCamera: (id)sender
    {
        if ([UIImagePickerController isSourceTypeAvailable:
             UIImagePickerControllerSourceTypeCamera])
        {
            UIImagePickerController *imagePicker =
            [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.sourceType =
            UIImagePickerControllerSourceTypeCamera;
            imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                      (NSString *) kUTTypeImage,
                                      nil];
            imagePicker.allowsEditing = NO;
            [self presentModalViewController:imagePicker
                                    animated:YES];
            newMedia = YES;
        }
    }

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self.popoverController dismissPopoverAnimated:true];

    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    [self dismissModalViewControllerAnimated:YES];
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) 
    {
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    imageView.image = image;
        if (newMedia)
            UIImageWriteToSavedPhotosAlbum(image, self,  
                                           @selector(image:finishedSavingWithError:contextInfo:),nil);
    }

}
-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
 contextInfo:(void *)contextInfo
{
    if (error) 
    {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: @"Save failed"
                              message: @"Failed to save image"
                              delegate: self
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
        [alert show];

    }
}
    - (IBAction) useCamera: (id)sender
    {
        if ([UIImagePickerController isSourceTypeAvailable:
             UIImagePickerControllerSourceTypeCamera])
        {
            UIImagePickerController *imagePicker =
            [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.sourceType =
            UIImagePickerControllerSourceTypeCamera;
            imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                      (NSString *) kUTTypeImage,
                                      nil];
            imagePicker.allowsEditing = NO;
            [self presentModalViewController:imagePicker
                                    animated:YES];
            newMedia = YES;
        }
    }

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self.popoverController dismissPopoverAnimated:true];

    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    [self dismissModalViewControllerAnimated:YES];
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) 
    {
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    imageView.image = image;
        if (newMedia)
            UIImageWriteToSavedPhotosAlbum(image, self,  
                                           @selector(image:finishedSavingWithError:contextInfo:),nil);
    }

}
-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
 contextInfo:(void *)contextInfo
{
    if (error) 
    {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: @"Save failed"
                              message: @"Failed to save image"
                              delegate: self
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
        [alert show];

    }
}
痴情 2024-11-16 15:31:08

与 AVFoundation 相关的 Apple 文档和示例代码有几个错误。请参阅 iOS 4:使用 AVFoundation 拍摄实时预览照片,了解实际从实时预览。

The Apple docs and sample code related to AVFoundation has several mistakes. See iOS 4: Take photos with live preview using AVFoundation for code that actually captures images from a live preview.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文