gpt4 book ai didi

iphone - 如何将视频或电影文件显示到 UIImagePickerController 中?

转载 作者:行者123 更新时间:2023-12-03 20:01:15 24 4
gpt4 key购买 nike

我正在使用 UIImagePickerController,它使用户能够选择现有照片或使用相机当时拍摄图像。我可以使用 UIImageView 在我的应用程序中显示该图像。

现在我也想将这种能力用于电影。但我找不到任何方法可以在我的应用程序中将所选电影显示为图像,就像“照片”应用程序一样。如您所知,您可以在同一列表中查看照片和电影。

最佳答案

-(IBAction) selectImageSelected : (id)sender
{
actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Take Picture", @"Select from gallery", nil];
[actionSheet showInView:self.parentViewController.tabBarController.view];
}

- (void)actionSheet:(UIActionSheet *)_actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex==0)
{
if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] )
{
[AlertHandler showAlertMessage:[ErrorMessages getCameraNotFoundMsg] withTitle:@"No Camera Detected"];
return;
}
else
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
}
}
else if(buttonIndex==1)
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];
[self presentModalViewController:imagePicker animated:YES];
}
else
{
[actionSheet dismissWithClickedButtonIndex:2 animated:YES];
}
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

if ([mediaType isEqualToString:@"public.image"]){

// UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];

UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

NSLog(@"found an image");

// [UIImageJPEGRepresentation(image, 1.0f) writeToFile:[self findUniqueSavePath] atomically:YES];

// SETIMAGE(image);

CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);

}

else if ([mediaType isEqualToString:@"public.movie"]){

NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];

NSLog(@"found a video");

NSData *webData = [NSData dataWithContentsOfURL:videoURL];

//NSData *video = [[NSString alloc] initWithContentsOfURL:videoURL];

// [webData writeToFile:[self findUniqueMoviePath] atomically:YES];

CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);
CGSize sixzevid=CGSizeMake(imagePicker.view.bounds.size.width,imagePicker.view.bounds.size.height-100);
UIGraphicsBeginImageContext(sixzevid);
[imagePicker.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
eventButton.imageView.image=viewImage;
// NSLog(videoURL);

}

[picker dismissModalViewControllerAnimated:YES];

}

/*
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo1
{
[imagePicker dismissModalViewControllerAnimated:YES];
imagePicker.view.hidden = YES;
eventButton.imageView.image = image;
imageSelected = YES;
}
*/
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[imagePicker dismissModalViewControllerAnimated:YES];
imageSelected = NO;
}

关于iphone - 如何将视频或电影文件显示到 UIImagePickerController 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2996893/

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