I'm using an imagePickerController to replace my existing images inside my view. The function works within the same IB-file. However I'd like to load the chosen image in another IB-File as well. I think that the solution is to give a name to the image when saved. After it is saved I'd like to call the image (by name) from my memory within my other IB-file.
Here's a snippit of code I'm using within the photopicker IB-file
-(IBAction)setPhoto{
image1.image = fotoView.image;
}
-(IBAction)getCameraPicture:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = (sender == takePictureButton) ? UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController: picker animated:YES];
[picker release];
}
-(IBAction)selectExitingPicture
{
if([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker= [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:YES];
fotoView.image = image;
NSData* imdata = UIImagePNGRepresentation ( image );
UIImage* im8 = [UIImage imageWithData:imdata];
UIImageWriteToSavedPhotosAlbum(im8, nil, nil, nil);
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
}
within my other class I'd like to call this image by means of:
if (#some condition){
UIImage *img = [UIImage imageNamed:#"Name of the image.png"];
[image1 setImage:img];
}
Help is greatly appreciated
Method for image picking and saving it to the directory:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo {
[picker dismissModalViewControllerAnimated:YES];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pngFilePath = [NSString stringWithFormat:#"%#/MyName.png",docDir];
NSData *data = [NSData dataWithData:UIImagePNGRepresentation(image)];
[data writeToFile:pngFilePath atomically:YES];
}
Lateron you can call it by using:
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pngFilePath = [NSString stringWithFormat:#"%#/MyName.png",docDir];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:pngFilePath];
Related
im trying to make an app that has 4 ImageViews and I want to allow the user to change the background on the different ImageViews by pressing an UIButton below each ImageView. I have written a code for this from a tutorial showing to do this with just one ImageView. I just copied and pasted 4 times for each button and changed some variables. But when I run it only the first ImageView changes its picture even if I press UIButton for 2nd, 3rd or 4th ImageView. here the code:
#import "ViewController.h"
#interface ViewController ()
{
UIImagePickerController *imagePickerController;
UIImagePickerController *imagePickerController2;
UIImagePickerController *imagePickerController3;
UIImagePickerController *imagePickerController4;
}
#end
#implementation ViewController
#synthesize firstImageView, secondImageView, thirdImageView, fourthImageView;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction)firstChangeButton:(id)sender
{
imagePickerController = [[UIImagePickerController alloc]init];
[imagePickerController setDelegate:self];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController animated:YES completion:nil];
}
- (IBAction)secondChangeButton:(id)sender
{
imagePickerController2 = [[UIImagePickerController alloc]init];
[imagePickerController2 setDelegate:self];
[imagePickerController2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController2 animated:YES completion:nil];
}
- (IBAction)thirdChangeButton:(id)sender
{
imagePickerController3 = [[UIImagePickerController alloc]init];
[imagePickerController3 setDelegate:self];
[imagePickerController3 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController3 animated:YES completion:nil];
}
- (IBAction)fourthChangeButton:(id)sender
{
imagePickerController4 = [[UIImagePickerController alloc]init];
[imagePickerController4 setDelegate:self];
[imagePickerController4 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController4 animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image1 = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *data = UIImagePNGRepresentation(image1);
NSString *myGrabbedImage = #"myGrabbedImage.png";
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path objectAtIndex:0];
NSString *fullPathToFile = [documentDirectory stringByAppendingPathComponent:myGrabbedImage];
[data writeToFile:fullPathToFile atomically:YES];
[[self firstImageView]setImage:image1];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerController2:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info2
{
UIImage *image2 = [info2 objectForKey:UIImagePickerControllerOriginalImage];
NSData *data2 = UIImagePNGRepresentation(image2);
NSString *myGrabbedImage2 = #"myGrabbedImage2.png";
NSArray *path2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory2 = [path2 objectAtIndex:0];
NSString *fullPathToFile2 = [documentDirectory2 stringByAppendingPathComponent:myGrabbedImage2];
[data2 writeToFile:fullPathToFile2 atomically:YES];
[[self secondImageView]setImage:image2];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerController3:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info3
{
UIImage *image3 = [info3 objectForKey:UIImagePickerControllerOriginalImage];
NSData *data3 = UIImagePNGRepresentation(image3);
NSString *myGrabbedImage3 = #"myGrabbedImage3.png";
NSArray *path3 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory3 = [path3 objectAtIndex:0];
NSString *fullPathToFile3 = [documentDirectory3 stringByAppendingPathComponent:myGrabbedImage3];
[data3 writeToFile:fullPathToFile3 atomically:YES];
[[self thirdImageView]setImage:image3];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerController4:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info4
{
UIImage *image4 = [info4 objectForKey:UIImagePickerControllerOriginalImage];
NSData *data4 = UIImagePNGRepresentation(image4);
NSString *myGrabbedImage4 = #"myGrabbedImage4.png";
NSArray *path4 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory4 = [path4 objectAtIndex:0];
NSString *fullPathToFile4 = [documentDirectory4 stringByAppendingPathComponent:myGrabbedImage4];
[data4 writeToFile:fullPathToFile4 atomically:YES];
[[self fourthImageView]setImage:image4];
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
How should i apply it for all 4 ImageViews?
Thanks in advance!
The problem is that all image pickers will call the same delegate method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
When you set the delegate for the image picker controller like so:
[imagePickerController setDelegate:self];
You basically tell the image picker controller that self will be able to respond to the image picker delegate methods.
As you can see in the UIImagePickerControlDelegate, there's no such thing as:
– imagePickerController2:didFinishPickingMediaWithInfo:
and so on.
As a start, I would suggest rewriting your delegate method like this:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image1 = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *data = UIImagePNGRepresentation(image1);
NSString *myGrabbedImage = #"myGrabbedImage.png";
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path objectAtIndex:0];
NSString *fullPathToFile = [documentDirectory stringByAppendingPathComponent:myGrabbedImage];
[data writeToFile:fullPathToFile atomically:YES];
if (picker == imagePickerController) {
[[self firstImageView]setImage:image1];
} else if (picker == imagePickerController2) {
[[self secondImageView]setImage:image1];
} else if (picker == imagePickerController3) {
[[self thirdImageView]setImage:image1];
} else {
[[self fourthImageView]setImage:image1];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
This way, all image picker images will be handled by the same method, thus reducing the amount of code.
I am using ELCimagepicker to attach multiple image to an email but I'm not sure how to make every NSData unique so i can attach them to my email.
>
- (void)launchController {
ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] initWithNibName:#"ELCAlbumPickerController" bundle:[NSBundle mainBundle]];
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
[albumController setParent:elcPicker];
[elcPicker setDelegate:self];
[self presentModalViewController:elcPicker animated:YES];
}
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info {
[self dismissModalViewControllerAnimated:YES];
int i = 0;
for(NSDictionary *dict in info) {
i++;
UIImageView *imageview = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]];
NSData *name = UIImageJPEGRepresentation(imageview, 1.0);
}
}
Get the app from this link
https://github.com/elc/ELCImagePickerController
and following changes from the code
using for loop
-(IBAction)launchController
{
ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] initWithNibName:#"ELCAlbumPickerController" bundle:[NSBundle mainBundle]];
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
[albumController setParent:elcPicker];
[elcPicker setDelegate:self];
ELCImagePickerDemoAppDelegate *app = (ELCImagePickerDemoAppDelegate *)[[UIApplication sharedApplication] delegate];
[app.viewController presentModalViewController:elcPicker animated:YES];
[elcPicker release];
[albumController release];
[self buttonPressed];
}
- (void)buttonPressed
{
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
// Delegate is self
imagePicker.delegate = self;
// Allow editing of image ?
imagePicker.allowsImageEditing = NO;
// Show image picker
[self presentModalViewController:imagePicker animated:YES];
}
- (void)emailImage:(UIImage *)image
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
// Set the subject of email
[picker setSubject:#"Picture from my iPhone!"];
// Add email addresses
// Notice three sections: "to" "cc" and "bcc"
[picker setToRecipients:[NSArray arrayWithObjects:#"emailaddress1#domainName.com", #"emailaddress2#domainName.com", nil]];
[picker setCcRecipients:[NSArray arrayWithObject:#"emailaddress3#domainName.com"]];
[picker setBccRecipients:[NSArray arrayWithObject:#"emailaddress4#domainName.com"]];
// Fill out the email body text
NSString *emailBody = #"I just took this picture, check it out.";
for (int i=0; i<[imagedelegate.imgarray count]; i++)
{
UIImageView *image=[[UIImageView alloc] init];
image=[imagedelegate.imgarray objectAtIndex:i];
// This is not an HTML formatted email
[picker setMessageBody:emailBody isHTML:NO];
// Create NSData object as PNG image data from camera image
NSData *data = UIImagePNGRepresentation(image);
// Attach image data to the email
// 'CameraImage.png' is the file name that will be attached to the email
[picker addAttachmentData:data mimeType:#"image/png" fileName:#"CameraImage"];
// Show email view
[self presentModalViewController:picker animated:YES];
// Release picker
[picker release];
}
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
// Dismiss the camera
[self dismissModalViewControllerAnimated:YES];
// Pass the image from camera to method that will email the same
// A delay is needed so camera view can be dismissed
[self performSelector:#selector(emailImage:) withObject:image afterDelay:1.0];
// Release picker
[picker release];
}
Download and drag the Objective-Zip, MiniZip and ZLib drag in to your project from this link http://code.google.com/p/objective-zip/downloads/list (Objective-zip).. import the files: ZipFile.h, ZipException.h, FileInZipInfo.h, ZipWriteStream.h, ZipReadStream.h, zlib.h
Use the following code:
NSString *stringPath1 = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]];
NSString *FileName=[stringPath1 stringByAppendingPathComponent:#"Your file name"];
NSString *stringPath=[stringPath1 stringByAppendingPathComponent:[#"Your file name" stringByAppendingFormat:#".zip"]];
NSArray *files = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:FileName error:&error];
ZipFile *zipFile = [[ZipFile alloc]initWithFileName:stringPath mode:ZipFileModeCreate];
for(int i = 0;i<files.count;i++){
id myArrayElement = [files objectAtIndex:i];
NSLog(#"add %#", myArrayElement);
NSString *path = [FileName stringByAppendingPathComponent:myArrayElement];
NSDictionary *attributes = [[NSFileManager defaultManager]attributesOfItemAtPath:path error:&error];
NSDate *Date = [attributes objectForKey:NSFileCreationDate];
ZipWriteStream *streem = [zipFile writeFileInZipWithName:myArrayElement fileDate:Date compressionLevel:ZipCompressionLevelBest];
NSData *data = [NSData dataWithContentsOfFile:path];
[streem writeData:data];
[streem finishedWriting];
}
[zipFile close];
//This method Launches the picker to take the picture from camera.
-(IBAction)takeyouphoto:(id)sender
{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
// Create image picker controller
UIImagePickerController *imagePicker2 = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker2.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker2.delegate = self;
// Allow editing of image ?
imagePicker2.allowsEditing= NO;
// Show image picker
[self presentModalViewController:imagePicker2 animated:YES];
}
}
//This is ImagePicker Delegate method.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
#try {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *resultimage=nil;
//I am using iOS5, so we can not use NSAutoreleasePool
resultimage=[info objectForKey:UIImagePickerControllerOriginalImage] ;
//This Launches the HUD (Activity Indicator) because ImagePicker ususally takes 5
//seconds to launch image.
[self showHUD:resultimage];
}
}
[picker dismissModalViewControllerAnimated:YES];
}
-(void)showHUD:(UIImage *)resultimage
{
[[Singleton sharedmysingleton] stoptimer];
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Loading Image";
//HUD.detailsLabelText=#"Loading";
//Below call on showWhileExecuting of the MBProgressHuD class has its own NSAutoreleasePool
//Defined in MGProgressHUD class. it also runs the method showimageincell; in separate
//thread.
[HUD showWhileExecuting:#selector(showimagesincell:) onTarget:self withObject:resultimage animated:YES];
}
-(void)showimagesincell:(UIImage *)image
{
appDelegate.tabbarcontroller.tabBar.userInteractionEnabled=NO;
NSError *error;
UIImage *resultImage=[self scale:image toSize:image.size];
//UIImage *resultImage = [[UIImage alloc] initWithCGImage:imgRefCrop scale:1.0 orientation:resultimage.imageOrientation];
//resultimage.imageOrientation
NSData *imagedata=UIImageJPEGRepresentation(resultImage, 0.7);//(resultImage);
UIImage *smallimage=[self scale:image toSize:CGSizeMake(100, 100)];
NSData *smallimagedata=UIImageJPEGRepresentation(smallimage, 0.7);
/* NSString *imagetypeid=[Fetchsavefromcoredata getImagenameandImageidfromdatabase:#"Mobile_ImageType" attributename:#"imageType" predicate:imagetypetxtfield.text];
//write image to document directory
NSString *localImagedir=[photodirpath stringByAppendingPathComponent:selectedvinnumber];
NSString *datetime=[Singleton imagedateandtime];
NSString *imagename=[NSString stringWithFormat:#"%#_%#.png",imagetypeid,datetime];
NSString *localImagePath=[localImagedir stringByAppendingPathComponent:imagename];
[imagedata writeToFile:localImagePath atomically:YES];*/
[self performSelectorOnMainThread:#selector(updatetableview) withObject:nil waitUntilDone:NO];
}
-(void)updatetableview
{
[[Singleton sharedmysingleton] starttimer];
[self viewWillAppear:YES];
}
-(UIImage *)scale:(UIImage *)image toSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
//Above is all my code, I have tried to find it on diffrent forums but I have not fixed it yet.
//Any help will be appreciated. Thanks in advance
The white screen issue is fixed by keeping the image returned by the UIIMagePickerController delegate method into an #autoreleasepool (for iOS5). It solved the problem, we can not use NSAutoreleasePool in ARC code.
Here the line of code in didFinishPickingMediaWithInfo: delegate method
UIImage *resultimage=nil;
#autoreleasepool
{
//I am using iOS5, so we can not use NSAutoreleasePool
resultimage=[info objectForKey:UIImagePickerControllerOriginalImage] ;
}
Below the UIImagePickerController delegate method after implementing #autoreleasepool
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
#try {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *resultimage=nil;
#autoreleasepool
{
//I am using iOS5, so we can not use NSAutoreleasePool
resultimage=[info objectForKey:UIImagePickerControllerOriginalImage] ;
}
//This Launches the HUD (Activity Indicator) because ImagePicker ususally takes 5
//seconds to launch image.
[self showHUD:resultimage];
}
}
[picker dismissModalViewControllerAnimated:YES];
}
I have this code for send images on tweet. When I try the app, the picker works well but it doesn't grab the image. What's wrong?
- (IBAction)sendImageTweet:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsEditing = NO;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
NSData *imageData = UIImagePNGRepresentation(image);
[self dismissModalViewControllerAnimated:YES];
[tweetViewController addImage:(UIImage *)imageData];
[self presentModalViewController:tweetViewController animated:YES];
}
You should use the constant, not an NSString and the key.
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
I am using UIImagePickerController that gives user to be able select an existing photo or use the camera to take an image at that time. And i can show that image in my application with UIImageView.
Now i want to use this ability for movies also. But i couldn't find any way to show the selected movie as an image in my app, just like the Photos app. as you know you can see photos and movies in the same list.
-(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;
}
The -thumbnailImageAtTime:timeOption: method of MPMoviePlayerController looks like it might help you get an image to display.
To have the picker view with only movie files
replace
imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];
with
picker.mediaTypes = [NSArray arrayWithObject:#"public.movie"];