2011-12-06 60 views
0

我用这个代码从Facebook的个人资料得到的图像,并显示在UIImageView的检索图像iphone库

// 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拍摄的照片)。我不知道如何继续,请帮助

回答

2

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

UIImagePickerController Class Reference

+1

有关更多控制,请参阅资产库框架。它在很多方面都是“更现代的”,并提供了使用“UIImagePickerController”无法获得的东西,但它不提供“UIViewController”级别的API,因此需要实施更多的工作。 – smparkes

+0

我是初学者我只会使用UIImagePickerController xd – user567