检索图像在iPhone库



我使用这个代码从facebook个人资料获取图像,并显示在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];

我想做一个按钮,当点击时允许用户通过iPhone库中的图像更改图像(他用iPhone拍摄的照片…)。我不知道该怎么做,请帮帮我

访问用户的照片库最容易通过使用UIImagePickerController进行调解。您创建和配置实例,设置委托并以模式显示它。实现-imagePickerController:didFinishPickingMediaWithInfo,当用户选择图像时通知。然后,您可以将此图像保存在用户的文档目录中。

UIImagePickerController类参考

最新更新