gpt4 book ai didi

ios - UIImagePickerController 允许我拍摄照片和视频,但不允许我保存它们或 "use"它们

转载 作者:行者123 更新时间:2023-12-01 17:25:50 25 4
gpt4 key购买 nike

我现在正在开发一个简单的照片和视频捕捉应用程序。该应用程序成功地允许用户按下按钮拍摄照片或视频。但是,一旦您完成拍摄照片或视频,它会提供 2 个选项:“重拍”和“使用照片”或“使用视频”,具体取决于您使用的是哪一个。

如果用户点击“重新拍摄”,那么它只是让他们重新拍摄一张新照片或视频,但是当用户点击“使用照片”或“使用视频”时,它不会做任何事情。该应用程序只是将它们带回主应用程序屏幕。

我对如何访问“使用照片”/“使用视频”按钮感到困惑,以便我可以编辑它的代码并将图像和视频保存到相机胶卷。

这是我到目前为止的代码:

ViewController.h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@property UIImagePickerController * pickerController;

-(IBAction)showCameraUI;

@end

View Controller .m:
#import "ViewController.h"


@interface ViewController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];

NSLog(@"%ld", (long)UIImagePickerControllerSourceTypeCamera); }

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(IBAction)showCameraUI{

UIImagePickerController * pickerController = [[UIImagePickerController alloc]init];

pickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];

pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;


[self presentViewController:pickerController animated:YES completion:NULL];

}

@end

最佳答案

您可以使用 didFinishPickingMediaWithInfo UIImagePickerController 的代表保存图像。

为此,您需要这样做:

-(IBAction)showCameraUI
{
UIImagePickerController * pickerController = [[UIImagePickerController alloc]init];
pickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.delegate = self;
[self presentViewController:pickerController animated:YES completion:NULL];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// save photo
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);
}
[picker dismissModalViewControllerAnimated:YES];
}

关于ios - UIImagePickerController 允许我拍摄照片和视频,但不允许我保存它们或 "use"它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20789265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com