I am using AGImagePickerController for selecting the multiple images at a time and get its information. It is working fine and getting the selected image array like this:
ALAsset - Type:Photo, URLs:{\n \"public.jpeg\" = \"assets-library://asset/asset.JPG?id=C2CFE6EA-8B51-45BB-934A-486DDC1454B5&ext=JPG\";\n}", "ALAsset - Type:Photo, URLs:{\n \"public.png\" = \"assets-library://asset/asset.PNG?id=D8B1E72A-A53F-4DC6-B0EC-21508CB4FA00&ext=PNG\";\n}
But I don't know how to further use this to get the image and send it to facebook. If anyone know how to get the image from above url please help me out.
Thanks in advance.
In your
-(void)agImagePickerController:(AGImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
{
for(ALAsset *asset in info)
{
ALAssetRepresentation *rep = [asset defaultRepresentation];
UIImage *img = [UIImage imageWithCGImage:[rep fullResolutionImage]];
NSLog(#"%#",img);
}
}
Here are 2 screenshots
Related
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
#import "Photos/Photos.h"
In your imagePickerController function add the following to get the filename of the selected image from the Photo library:
NSURL *imagePath = [editingInfo objectForKey:UIImagePickerControllerReferenceURL];
PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:#[imagePath] options:nil];
NSString *filename = [[result firstObject] filename];
NSLog(#"[filename ] %#", filename );
The result is like this: [filename ] IMG_0012.JPG
I would like to know how to retrieve the filename of an image taken with the camera using UIImagePickerController.
I don't need to do anything with it, i just have to display the filename, like something you would see when you attach a file when you're sending an email.
So far, i'm using AssetsLibrary :
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[picker dismissViewControllerAnimated:YES completion:nil];
NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
// define the block to call when we get the asset based on the url (below)
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
{
ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
NSLog(#"[imageRep filename] : %#", [imageRep filename]);
self.photoNameLabel.text = [imageRep filename];
};
// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
self.photoLoaded = info[UIImagePickerControllerEditedImage];
[self viewWillLayoutSubviews];
}
But imageAsset will always be nil if it comes from the device camera, and if not, the image is named IMG_00XX.jpg, even if i downloaded it from the internet before, with a different name.
Can i get the name of a picture in an ios environment? If so, how am i supposed to do that?
There is no name when you take a photo with the camera. All there is is the in-memory UIImage instance. It's not associated with a file.
If you wish to add this camera image to an email as an attachment, give it whatever name you want such as "photo.jpg" or "picture.jpg" or anything else you wish to use.
All
I have a requirement to Upload a UIImage taken from Photo Gallery or Photo taken from Camera,
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:chosenImage,#"chosenImage", nil];
UIImage* selectedImage = [userInfo objectForKey:#"chosenImage"]
NSData *imageData = UIImagePNGRepresentation(selectedImage);
}
I am using imageData to upload it on server, I want to know is there any way to reduce the memory size of the UIImage without changing the quality. Please let me know.
I am trying to get the image filename from the camera. I have seen many, many posts about retrieving the filename using UIImagePickerControllerReferenceURL or UIImagePickerControllerMediaURL, but that only gets you a filename similar to: //asset/asset.JPG?id=D1D715A8-6956-49FF-AF07-CE60FE93AE32&ext=JPG. I believe this is because the image is not saved yet, thus a name like img0001.jpg in not available.
Does anyone know how to get the filename? I am as suing I need to do this after UIImageWriteToSavedPhotosAlbum, but I cannot seem to figure it out.
I have seen the question asked many times, but none seem to 'really' answer it, they just always give the filename from an image chosen from the picker not from the camera.
Thanks for any help
** UPDATE:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self.popoverController dismissPopoverAnimated:true];
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = image;
if (newMedia)
{
UIImageWriteToSavedPhotosAlbum(image,
self,
#selector(image:finishedSavingWithError:contextInfo:),
nil);
NSURL *refURL = [info valueForKey:UIImagePickerControllerMediaURL];
// define the block to call when we get the asset based on the url (below)
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
{
ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
NSLog(#"[imageRep filename] : %#", [imageRep filename]);
};
// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
}
}
}
My code above, but when imageRep filename is logged it is null.
With this code below, I can extract metadata from an image (pre-added to my project), and render the info as text. This is exactly what I want to do. The SYMetadata is created by pointing to an image via URL. initWithAbsolutePathURL. I want to do the same thing with a UIImage or maybe the image that is being loaded to the UIImage. How do I get the URL to the image that the picker selects? Or how do I create an "asset" from this incoming image?
The documentation describes initWithAsset. Have not figured out how to use it yet though, or if this is the right way to go for my purpose. Any help greatly appreciated.
NSURL *imageURL = [[NSBundle mainBundle] URLForResource:#"someImage" withExtension:#"jpg"];
SYMetadata *metadata = [[SYMetadata alloc] initWithAbsolutePathURL:imageURL];
[textView setText:[[metadata allMetadatas] description]];
Note: I tried adding an NSURL like this imageURL = [info valueForKey:#"UIImagePickerControllerReferenceURL"];, in the "pickerDidFinish" method but the metadata is null after I add this URL to the above code.
If you are using the imagePickerController, the delegate method will give you what you need
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if ([[info allKeys] containsObject:UIImagePickerControllerReferenceURL]){
// you will get this key if your image comes from a library
[self setMetaDataFromAssetLibrary:info];
} else if ([[info allKeys] containsObject:UIImagePickerControllerMediaMetadata]){
// if the image comes from the camera you get the metadata in it's own key
self.rawMetaData = [self metaDataFromCamera:info];
}
}
From Asset Library - bear in mind that it takes time to complete and has an asynchronous completion block, so you might want to add a completion flag to ensure you don't access the property before it has been updated.
- (void) setMetaDataFromAssetLibrary:(NSDictionary*)info
{
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL
resultBlock:^(ALAsset *asset) {
self.rawMetaData = asset.defaultRepresentation.metadata;
}
failureBlock:^(NSError *error) {
NSLog (#"error %#",error);
}];
}
From Camera:
- (NSDictionary*)metaDataFromCamera:(NSDictionary*)info
{
NSMutableDictionary *imageMetadata = [info objectForKey:UIImagePickerControllerMediaMetadata];
return imageMetadata;
}
Here is how to get metadata from a UIImage
- (NSDictionary*)metaDataFromImage:(UIImage*)image
{
NSData *jpegData = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0)];
return [self metaDataFromData:jpegData];
}
But take care - a UIImage can already stripped of much of the metadata from the original.. you will be better off getting the metadata from the NSData that was used to create the UIImage...
- (NSDictionary*)metaDataFromData:(NSData*)data
{
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
CFDictionaryRef imageMetaData = CGImageSourceCopyPropertiesAtIndex(source,0,NULL);
return (__bridge NSDictionary *)(imageMetaData);
}
If you've an ALAsset (in my sample _detailItem), you can have metadata in this way:
NSDictionary *myMetadata = [[_detailItem defaultRepresentation] metadata];