To understand my question please go through following:
- In my application user first taps on a button.
- Image picker controller is displayed
- user selects images / an image from it.
- all that images must be saved to my iPhone application.
I have already implemented this and for doing this I have implemented following code.
-(IBAction)setPhoto:(id)sender {
facPhotoPicker=[[UIImagePickerController alloc]init];
facPhotoPicker.delegate=self;
facPhotoPicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
facPhotoPicker.allowsImageEditing=YES;
facPhotoPicker.navigationBar.barStyle=UIBarStyleBlackOpaque;
[self presentModalViewController:facPhotoPicker animated:YES];
}
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {
NSData *imgData=UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
UIImage *img=[[UIImage alloc] initWithData:imgData];
facImgView.image=img;
[img release];
NSString *str=[NSString stringWithFormat:@"%i.jpg",[currentFaculty facultyNo]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0], str];
[imgData writeToFile:path atomically:YES];
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
But the problem is the user’s iPhone may have larger images.
I don’t want to store that large images within application.
for example
- user selects an image having size of 1200 x 800
-
But I want only 80 x 80 size image
- selected images should be down sized to my requirement / 8 mb image to less then 500 kb
- how to store image within resource directory instead of storing in documents directory?
This is solved.
The main key for downsizing. I downsized an image up to 116 kb.