如何将UIView转换为UIImage以添加到UIImageView?

时间:2014-03-18 19:34:39

标签: ios uiview uiimage cgcontext

我正在拍摄我视图区域的快照并将其设置为新的UIView。

UIView *currView = [self.view resizableSnapshotViewFromRect:mp.moviePlayer.view.frame afterScreenUpdates:YES withCapInsets:UIEdgeInsetsZero];
    [currView setFrame:CGRectMake(0, 0, 204, 128)];

然后我尝试使用以下方法设置UIIamgeView图像:

[image2 setImage:[self getUIImageFromThisUIView:currView]];

-(UIImage*)getUIImageFromThisUIView:(UIView*)aUIView
{
    UIGraphicsBeginImageContext(aUIView.bounds.size);
    [aUIView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return viewImage;
}

但它没有将UIImageView的图像设置为任何东西? 提前致谢

0 个答案:

没有答案