Reputation: 241
-(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"];
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);
}
else
{
NSLog(@"no image name found");
}
//commented ashok
NSURL *resourceURL = [info objectForKey:UIImagePickerControllerMediaURL];
resourceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *assetLibrary = [ALAssetsLibrary new];
[assetLibrary assetForURL:resourceURL
resultBlock:^(ALAsset *asset) {
// get data
ALAssetRepresentation *assetRep = [asset defaultRepresentation];
CGImageRef cgImg = [assetRep fullResolutionImage];
filename = [assetRep filename];
NSLog(@"file name is:%@", filename);
}
failureBlock:^(NSError *error) {
NSLog(@"%@", error);
}];
}
-(void)send message
{
NSLog(@"image name is:%@",filename);
//image name is: IMG_0004.JPG
senderImgName=[UIImage imageNamed:filename];
NSLog(@"sender image name is :%@",senderImgName);
//sender image name is: null
}
Upvotes: 1
Views: 714
Reputation: 4158
Try this
//This will show the picker
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
//Deprecated In IOS6[self presentModalViewController:picker animated:YES];
[picker release];
//This delegate method will give you the selected image.
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
imgProfilePic.image = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissModalViewControllerAnimated:YES];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
Upvotes: 2
Reputation: 589
Try this
ALAssetRepresentation *assetRep = [asset defaultRepresentation];
CGImageRef cgImg = [assetRep fullResolutionImage];
UIImage* image = [UIImage imageWithCGImage:cgImg];
Upvotes: 1
Reputation: 72410
You need to give the UIImage
object to the imageView
not the name when you are using UIImagePickerController
, Change your code like this
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
self.imageView.image = image
}
Hope this will help you.
Upvotes: 2
Reputation: 19
Check if you added your image to the project. If image exist in the project, check if it is included for using target in properties.
Upvotes: 1