Reputation: 3842
i use this code to get image from facebook profile and show it on UIImageView
// Get the profile image
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[result objectForKey:@"pic"]]]];
// Resize, crop the image to make sure it is square and renders
// well on Retina display
float ratio;
float delta;
float px = 100; // Double the pixels of the UIImageView (to render on Retina)
CGPoint offset;
CGSize size = image.size;
if (size.width > size.height) {
ratio = px / size.width;
delta = (ratio*size.width - ratio*size.height);
offset = CGPointMake(delta/2, 0);
} else {
ratio = px / size.height;
delta = (ratio*size.height - ratio*size.width);
offset = CGPointMake(0, delta/2);
}
CGRect clipRect = CGRectMake(-offset.x, -offset.y,
(ratio * size.width) + delta,
(ratio * size.height) + delta);
UIGraphicsBeginImageContext(CGSizeMake(px, px));
UIRectClip(clipRect);
[image drawInRect:clipRect];
UIImage *imgThumb = UIGraphicsGetImageFromCurrentImageContext();
[imgThumb retain];
imageFb=imgThumb;
[profilePhotoImageView setImage:imgThumb];
I want to make a button, when clicked allows the user to change the image by an image in the library of the iPhone (photos he took with the iphone ..) . I have no idea how I should proceed, help please
Upvotes: 0
Views: 304
Reputation: 30846
Access to the user's photo library is most easily mediated with the use of UIImagePickerController
. You create and configure and instance, set a delegate and display it modally. Implement -imagePickerController:didFinishPickingMediaWithInfo
to be notified when the user selects an image. You can then persist this image in the user's documents directory.
UIImagePickerController Class Reference
Upvotes: 2