如何将 FBProfilePictureView 转换为 UIImage? [英] How can I convert FBProfilePictureView to an UIImage?

查看:26
本文介绍了如何将 FBProfilePictureView 转换为 UIImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 FBProfilePictureView 一切正常,但我需要从 FBProfilePictureView 获取该图片并将其转换为 UIImage.

Everything is working fine with FBProfilePictureView but I need to get that picture from FBProfilePictureView and turn it into an UIImage.

我该怎么做?

我试过用这个:

UIGraphicsBeginImageContext(self.profilePictureView.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.TestPictureOutlet.image = viewImage;

但这对我的解决方案不起作用.

But this doesnt work for my solution.

推荐答案

FBProfilePictureView 是一个 UIView,这个 UIView 包含一个 UIImageView,也就是你的图片,你可以从那个 UIImageView 获取 UIImage:

FBProfilePictureView is a UIView, this UIView contains a UIImageView, that is your image, you can get the UIImage from that UIImageView:

profilePictureView 是一个 FBProfilePictureView

profilePictureView is a FBProfilePictureView

UIImage *image = nil;

for (NSObject *obj in [profilePictureView subviews]) {
    if ([obj isMemberOfClass:[UIImageView class]]) {
        UIImageView *objImg = (UIImageView *)obj;
        image = objImg.image;
        break;
    }
}

添加另一种更快的方式,但做同样的事情

add another way more quickly but do the same thing

__block UIImage *image = nil;

[self.view.subviews enumerateObjectsUsingBlock:^(NSObject *obj, NSUInteger idx, BOOL *stop) {
    if ([obj isMemberOfClass:[UIImageView class]]) {
        UIImageView *objImg = (UIImageView *)obj;
        image = objImg.image;
        *stop = YES;
    }
}];

这篇关于如何将 FBProfilePictureView 转换为 UIImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆