I'm doing a pick a images from iPhone photo library or in other way from camera roll. I've done that without any problem. But I need to retrieve the picking the image name from the library. but I cant able to pick the image name from gallery. My requirement is I want to pick the image and image name from photo gallery and send the chat wall.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage *image =[[UIImage alloc] init];
image =[info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSURL *imagePath = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
//Here I am able to get the image path like this: assets-library://asset/asset.JPG?id=9F983DBA-EC35-42B8-8773-B597CF782EDD&ext=JPG
imageName = [imagePath lastPathComponent];
NSData *imageData;
NSString *extensionOFImage =[imageName substringFromIndex:[imageName rangeOfString:@"."].location+1 ];
if ([extensionOFImage isEqualToString:@"jpg"])
{
imageData =UIImagePNGRepresentation(image);
}
else
{
imageData = UIImageJPEGRepresentation(image, 1.0);
}
int imageSize=imageData.length/1024;
NSLog(@"imageSize--->%d", imageSize);
if (imageName!=nil) {
NSLog(@"imageName--->%@",imageName);
//here the imageName is showing like this “asset.jpg”..
}
else
{
NSLog(@"no image name found");
}
}
-(void)sendMessage:(NSString *)messageTxt {
str=@"Ryan";
mesText=messageTxt;
senderImgName=[UIImage imageNamed:imageName];
//here the imageName is showing like this = asset.jpg
//but senderImgName= null.
NSString *str1=imageName;
NSLog(@"sender image name is:%@",senderImgName);
imgData=[NSData dataWithData:UIImageJPEGRepresentation(senderImgName, 0)];
finalImagePath=[imgData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
NSLog(@"Final image path is:%@", finalImagePath);
}
Use the Photos framework and import Photos/Photos.h
In your imagePickerController function add the following to get the filename of the selected image from the Photo library:
The result is like this: [filename ] IMG_0012.JPG