将某视图View转换为UIImage

+ (UIImage *)getSharedScreenView{

    UIWindow *screenWindow = [[UIApplication sharedApplication]keyWindow];
ScreenView *currentView = [[[self class] alloc] init];
currentView.frame = screenWindow.bounds;
[screenWindow addSubview:currentView]; //UIGraphicsBeginImageContext() 图片会失真模糊
UIGraphicsBeginImageContextWithOptions(screenWindow.frame.size, NO, 0.0);//图片不模糊
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* viewImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[currentView removeFromSuperview];
//UIImageWriteToSavedPhotosAlbum(viewImage,nil,nil,nil); //写入到相册
return viewImage;
}
上一篇:Intellj idea 安装JUnit


下一篇:201621123080《java程序设计》第六周作业总结