Fgallery save image to iPhone - iphone

Hi Sorry for being a noob but I'm learning. I have Fgallery working in my app but now I want to connect a bar button to an action to save the image to the phone. I need some code that gives me the current image (in the large image view) I hope someone can help me out with this. This is what I have:
- (void)handleEditCaptionButtonTouch:(id)sender {
// here we could implement some code to change the caption for a stored image
[networkGallery saveImageAtIndex:[networkGallery currentIndex]];
}
And here I have an image hard-coded but I need the current image:
- (void)saveImageAtIndex:(NSUInteger)index
{
UIImage *image = [UIImage imageNamed:#"background.png"];
if(image != nil){
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
}
return;
}
//saveImage method
-(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
[BT_debugger showIt:self:[NSString stringWithFormat:#"finished saving image: %#", #""]];
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];
[alert release];
}
Any help would be very appreciated.
Thanks in advance
DK

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
img.image = [info valueForKey:#"UIImagePickerControllerOriginalImage"];
[self dismissModalViewControllerAnimated:YES];
}

If someone else is looking for an answer. Here it is:
FGalleryPhoto *photo = [_photoLoaders objectForKey:[NSString stringWithFormat:#"%i", index]];
UIImage *saveImage = [photo fullsize];

In code above, in the stringWithFormat method, replace index with _currentIndex
FGalleryPhoto *photo = [_photoLoaders objectForKey:[NSString stringWithFormat:#"%i", _currentIndex]];
UIImage *saveImage = [photo fullsize];

Related

how to prevent saving picture from camera roll again

May be this question is too easy or I did not know how easy it will be.
I have an actionsheet to allow the user to choose how if they want to take a photo or select from camera.
The app will save user taken photo regardless is selected from camera roll or taken from camera. Am I missing something?
Thanks for reading my question.
#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];
}
Try this code.. Its working properly from my side.
- (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];
}
you need to implement UIImagePickerControllerDelegate
Check this function
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{}
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:#"public.image"]){
UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
}
Now use this UIImage
To save this Image You have to specify a path
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];

writeImageToSavedPhotosAlbum:metadata:completionBlock:

I use the method writeImageToSavedPhotosAlbum:metadata:completionBlock: save taken picture to photo album,code is:
-(void)savePhotoToAlbum{
CGImageRef imageRef=[imageView image].CGImage;
NSDictionary *currentDic=[self getLocation];
NSDictionary *metadata=[NSDictionary dictionaryWithDictionary:currentDic];
ALAssetsLibrary *library=[[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:imageRef metadata:metadata completionBlock:^(NSURL *assetURL,NSError *error){
if(error == nil)
{
UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:nil message:#"Save success!" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
else
{
UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:nil message:#"Save failure!" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}];
[library release];
}
.The method getLocation that is get user's current location!That can save success!Then I want to pick taken picture from photo album use UIImagePickerController! Code is :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{ if([picker sourceType]==UIImagePickerControllerSourceTypeSavedPhotosAlbum)//picker image delegate
{
NSString *mediaType=[info objectForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:#"public.image"])
{
NSDictionary *metadata=[info objectForKey:UIImagePickerControllerMediaMetadata];
NSLog(#"%#",metadata);
}
}
}
Then log the metadata is null.That's why? And how do I get the metadata info which I saved?Thanks!
The metadata of the image will be available only if the sourceType is UIImagePickerControllerSourceTypeCamera.
See Ref. Look at the last paragraph in that page.
You can take log of metadata with AssetsLibrary framework:
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
...
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
if (url) {
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) {
CLLocation *location = [myasset valueForProperty:ALAssetPropertyLocation];
NSLog(#"\n\n\n____________________________\n");
NSLog(#"ORIENTATION: %#\n",[myasset valueForProperty:ALAssetPropertyOrientation]);
NSLog(#"LOCATION: %#\n",[myasset valueForProperty:ALAssetPropertyLocation]);
NSLog(#"DATE: %#\n",[myasset valueForProperty:ALAssetPropertyDate]);
NSLog(#"Duration: %#\n",[myasset valueForProperty:ALAssetPropertyDuration]);
NSLog(#"TYPE: %#\n",[myasset valueForProperty:ALAssetPropertyType]);
NSLog(#"\n____________________________\n\n\n");
//take coordinates only
CLLocationCoordinate2D coordinate = [location coordinate];
strCoord = [NSString stringWithFormat:#"long: %f; lat: %f;", coordinate.latitude, coordinate.longitude];
NSLog(#"%#", strCoord);
// location contains lat/long, timestamp, etc
// extracting the image is more tricky and 5.x beta ALAssetRepresentation has bugs!
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) {
NSLog(#"cant get image - %#", [myerror localizedDescription]);
};
ALAssetsLibrary *assetsLib = [[ALAssetsLibrary alloc] init];
[assetsLib assetForURL:url resultBlock:resultblock failureBlock:failureblock];
}
}
...
}

didFinishPickingMediaWithInfo return nil photo

I am working to capture an image that is returned in 4.0 using
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
// MediaType can be kUTTypeImage or kUTTypeMovie. If it's a movie then you
// can get the URL to the actual file itself. This example only looks for images.
//
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
// NSString* videoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
// Try getting the edited image first. If it doesn't exist then you get the
// original image.
//
if (CFStringCompare((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) {
UIImage* picture = [info objectForKey:UIImagePickerControllerEditedImage];
if (!picture)
picture = [info objectForKey:UIImagePickerControllerOriginalImage];
// **picture is always nil
// info dictionary count = 1
}
}
What is happening is that the info dictionary always returns with a single entry:
{
UIImagePickerControllerMediaType =
"public.image";
which is great, but there is never an image.
I was using a great example from this forum to do this, and I am pretty sure the calls are correct, but never an image.
Thanks in advance!
I know this is many months later, but I struggled with this for hours, and found this same question all over this site and iphonedevsdk.com, but never with a working answer.
To summarize, if the image was picked from the camera roll/photo library it worked fine, but if the image was a new photo take with the camera it never worked. Well, here's how to make it work for both:
You have to dismiss and release the UIImagePickerController before you try to do anything with the info dictionary. To be super-clear:
This DOES NOT work:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
// No good with the edited image (if you allowed editing)
myUIImageView.image = [info objectForKey:UIImagePickerControllerEditedImage];
// AND no good with the original image
myUIImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
// AND no doing some other kind of assignment
UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];
[picker dismissModalViewControllerAnimated:YES];
[picker release];
}
In all of those cases the image will be nil.
However, via the magic of releasing the UIImagePickerController first...
This DOES work:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
[picker release];
// Edited image works great (if you allowed editing)
myUIImageView.image = [info objectForKey:UIImagePickerControllerEditedImage];
// AND the original image works great
myUIImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
// AND do whatever you want with it, (NSDictionary *)info is fine now
UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];
}
Crazy simple, but that's all there is to it.
whilst Matthew Frederick's answer is most popular and has long been the appropriate response, as of iOS 5.0, apple made available dismissViewControllerAnimated:completion:, to replace the now deprecated (as of iOS 6.0) dismissViewControllerAnimated:.
performing the image info dictionary retrieval in the completion block should hopefully make more sense to all.
to take his example from above, it would now look like:
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:^{
// Edited image works great (if you allowed editing)
myUIImageView.image = [info objectForKey:UIImagePickerControllerEditedImage];
// AND the original image works great
myUIImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
// AND do whatever you want with it, (NSDictionary *)info is fine now
UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];
}];
}
I've tried all above, but no luck on iPad 6.0/6.1 simulator, however i've found that info contains "UIImagePickerControllerReferenceURL" key and here is my code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:NULL];
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
if(NULL == image){
[MyImageLoader loadImageFromAssertByUrl:[info objectForKey:#"UIImagePickerControllerReferenceURL"]
completion:^(UIImage* img){
//img not null here
}];
}else{
//image not null here
}
}
and code for loadImageFromAssertByUrl is:
+(void) loadImageFromAssertByUrl:(NSURL *)url completion:(void (^)(UIImage*)) completion{
ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *rep = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
UIImage* img = [UIImage imageWithData:data];
completion(img);
} failureBlock:^(NSError *err) {
NSLog(#"Error: %#",[err localizedDescription]);
}];
}
There's also a known bug with some versions of XCode and Mountain Lion. Check your console for this message:
2013-01-17 21:36:34.946 3sure-ios[5341:1803] Named service 'com.apple.PersistentURLTranslator.Gatekeeper' not found. assetsd is down or misconfigured. Things will not work the way you expect them to.
It probably won't work if that message appears. Check your app at the actual iOS device.
Nevetheless, restarting both simulator and XCode seems to fix the issue.
I had the same symptoms, but in my case it turned out I had a category on something in the UIImagePickerController hierarchy that overrode "uuid" or "setUUID"? I guess CoreData needs these methods or it gets very, very confused, and the asset library is all CoreData stuff.
use
[[UIImagePickerController alloc] init];
instead of
[[UIImagePickerController alloc] initWithNibName:(NSString *) bundle:(NSBundle *)];
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:NULL];
//Image picker for nil value
UIImage* selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(#"my Info :: %#", info);
if(NULL == selectedImage){
UIImage * selectedImage = [PhotoViewController loadImageFromAssertByUrl:[info objectForKey:#"UIImagePickerControllerReferenceURL"]
completion:^(UIImage * selectedImage){
//img not null here
NSLog(#"img2 ::: %#", selectedImage);
uploadImg.image = selectedImage;
[self.view addSubview:PermissionView];
}];
}else{
//image not null here
NSLog(#"Up IMG00 :: %#", uploadImg.image);
NSLog(#"Sel IMG00 :: %#", selectedImage);
uploadImg.image = [selectedImage retain];
NSLog(#"Up IMG22 :: %#", uploadImg.image);
NSLog(#"Sel IMG22 :: %#", selectedImage);
}
}
+(UIImage *) loadImageFromAssertByUrl:(NSURL *)url completion:(void (^)(UIImage*)) completion{
__block UIImage* img;
ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *rep = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
img = [UIImage imageWithData:data];
completion(img);
NSLog(#"img ::: %#", img);
} failureBlock:^(NSError *err) {
NSLog(#"Error: %#",[err localizedDescription]);
}];
return img;
}
Following Steps needs to be followed:
1) Make UIActionSheet
2) On selection necessary source type - load resrouces
3) didFinishPickingMediaWithInfo - set image from image Dictionary recieved
- (IBAction)actionButtonUpload:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self
cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Camera",#"Photo Library", nil];
[actionSheet showInView:self.view];
}
#pragma mark -- UIActionSheet Delegate
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
UIAlertView *alert;
switch (buttonIndex) {
case 0:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
NSLog(#"No camera!");
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
} else {
alert = [[UIAlertView alloc]initWithTitle:#"Alumnikonnect" message:#"Camera is not available, please select a different media" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
}
break;
case 1:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
} else {
alert = [[UIAlertView alloc]initWithTitle:#"Alumnikonnect" message:#"Photolibrary is not available, please select a different media" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
}
break;
}
}
#pragma mark - Image picker delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.imageEventPic.layer.cornerRadius = self.imageEventPic.frame.size.height /2;
self.imageEventPic.layer.masksToBounds = YES;
self.imageEventPic.layer.borderWidth = 0;
self.imageEventPic.layer.borderWidth = 1.0f;
self.imageEventPic.layer.borderColor = [UIColor colorWithRed:0.212 green:0.255 blue:0.302 alpha:1.000].CGColor;
self.labelUploadPic.hidden = YES;
self.imageEventPic.image = info[UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
-(UIImage*)imageWithImage:(UIImage*)image
scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}

How do I Assign a Name to a Photo Saved in the Photo Library?

I am currently working on a project in which I have to save an image to the photo library and assign a name to each captured image. I know how to save the image, but how do you assign a name to the ones saved in the library?
My code:
-(void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
imgglobal =imageView.image;
//for saving image in photo library
UIGraphicsBeginImageContext(self.imageView.bounds.size);
[self.imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
UIGraphicsEndImageContext();
UIImage *image1=imageView.image;
[self imageSavedToPhotosAlbum:image1 didFinishSavingWithError:nil contextInfo: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(#"OK", #"")
otherButtonTitles:nil];
[alert show];
[alert release];
}
The photos in the photo library does not contain any names. And you can't create a folder in the photo library either. If you really need a name to the photos, put it inside ~/Documents and implement your own chooser.

how to show video or movie file into UIImagePickerController?

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"];