IOS 将UIView转成UIImage

来源:互联网 发布:6878游戏源码 编辑:程序博客网 时间:2024/05/16 00:35

+(UIImage*) imageOfView:(UIView*) view isRetain:(BOOL) retain{

   float scale = 1.0;

   if (retain == YES) {

        scale =2.0;

    }

    UIGraphicsBeginImageContextWithOptions(view.frame.size,NO, scale); 

    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

   return image;

}

很简单,当我们传入UIWindow的实例时,得到的图片即是我们的程序截图了

原创粉丝点击