IOS UIGraphicsBeginImageContextWithOptions 版本适配问题
来源:互联网 发布:求最短路径的算法 编辑:程序博客网 时间:2024/06/05 03:50
CGFloat scale = 1.0;if([[UIScreen mainScreen]respondsToSelector:@selector(scale)]) { CGFloat tmp = [[UIScreen mainScreen]scale]; if (tmp > 1.5) { scale = 2.0; }} if(scale > 1.5) { UIGraphicsBeginImageContextWithOptions(_launcherView.frame.size, NO, scale);} else { UIGraphicsBeginImageContext(_launcherView.frame.size);}[_launcherView.layer renderInContext:UIGraphicsGetCurrentContext()];UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();CGRect upRect = CGRectMake(0, 0, _launcherView.frame.size.width*scale, (diff - offset)*scale);CGImageRef imageRefUp = CGImageCreateWithImageInRect([screenshot CGImage], upRect);[self.screenshot1 setFrame:CGRectMake(0, 0, screenshot1.frame.size.width, diff - offset)];[screenshot1 setContentMode:UIViewContentModeTop];UIImage * img1 = [UIImage imageWithCGImage:imageRefUp];[self.screenshot1 setBackgroundImage:img1 forState:UIControlStateNormal];CGImageRelease(imageRefUp);CGRect downRect = CGRectMake(0, (diff - offset)*scale, _launcherView.frame.size.width*scale, (screenshot.size.height - diff + offset)*scale);CGImageRef imageRefDown = CGImageCreateWithImageInRect([screenshot CGImage], downRect);[self.screenshot2 setFrame:CGRectMake(0, screenshot1.frame.size.height , screenshot2.frame.size.width, _launcherView.frame.size.height - screenshot1.frame.size.height)];[screenshot2 setContentMode:UIViewContentModeTop];UIImage * img2 = [UIImage imageWithCGImage:imageRefDown];[self.screenshot2 setBackgroundImage:img2 forState:UIControlStateNormal];CGImageRelease(imageRefDown);
I've written this code to perform exactly the same thing described in the other post. It works on any iOS device with at least iOS 3.1.
_launcherView is the view that need to be photographed
转帖:http://stackoverflow.com/questions/5146008/how-to-use-uigraphicsbeginimagecontextwithoptions- IOS UIGraphicsBeginImageContextWithOptions 版本适配问题
- iOS Quart2D绘图之UIGraphicsBeginImageContextWithOptions基础
- iOS 之版本适配问题
- iOS不同版本适配问题
- UIGraphicsBeginImageContext和UIGraphicsBeginImageContextWithOptions实现iOS中的作图功能
- UIGraphicsBeginImageContext和UIGraphicsBeginImageContextWithOptions实现iOS中的截图功能
- UIGraphicsBeginImageContext和UIGraphicsBeginImageContextWithOptions实现iOS中的截图功能
- UIGraphicsBeginImageContext和UIGraphicsBeginImageContextWithOptions实现iOS中的截图功能
- iOS开发之不同版本适配问题
- iOS不同版本适配问题(#ifdef __IPHONE_7_0)
- iOS不同版本适配问题(#ifdef __IPHONE_7_0)
- IOS开发之不同版本适配问题
- iOS不同版本适配问题(#ifdef __IPHONE_7_0)
- iOS不同版本适配问题(#ifdef __IPHONE_7_0)
- iOS开发日志 之 iOS10版本适配问题
- iOS不同版本适配问题(#ifdef __IPHONE_7_0)
- iOS版本适配
- IOS:版本适配
- 一步一步复习数据结构和算法基础-稀疏矩阵基本操作
- 高精度阶乘(压缩5位保存)nyist28大数阶乘
- 使用CSpreadSheet应该注意的几个问题
- ubuntu SVN随记
- 防止表单回车form自动提交以及检测回车事件并处理
- IOS UIGraphicsBeginImageContextWithOptions 版本适配问题
- Windows API 多线程-学习笔记(一)
- ajax中的application/x-www-form-urlencoded中的使用
- TortoiseGit 使用教程
- Qt开发登录框的bug
- cmd命令
- 关于字符串转二进制、八进制、十进制、十六进制等的函数
- c++中的static
- 虚拟机装LINUX报错