CGBitmapContextCreate 在配备Retina的设备上绘制模糊的 解决方法
2013-05-16 09:05
633 查看
问题:在通过UIGraphicsGetCurrentContext得到的CGContextRef上画文字,在Retina设备上显示高清,但是通过CGBitmapContextCreate得到的CGContextRef上画文字,在Retina设备上显示很模糊原理:我们必须手动处理自己使用我们的x和y的比例因子为视网膜分辨率,
CGContextRef context = UIGraphicsGetCurrentContext(); CGImageRef image =CGBitmapContextCreateImage(context); NSLog(@"width of context %i", (int)CGImageGetWidth(image)); NSLog(@"height of context %i", (int)CGImageGetHeight(image));在新的iPad,禁用状态栏,打印结果为 2048和1536,iPad2将显示为1024和768),实际上,ios自动处理 1点= 4个像素。解决:
float scaleFactor = [[UIScreen mainScreen] scale];
CGSize size = CGSizeMake(768, 768);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, size.width * scaleFactor, size.height * scaleFactor, 8, size.width * scaleFactor * 4, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextScaleCTM(context, scaleFactor, scaleFactor);该示例是创建一个768×768 点的区域,新的iPad,这将是1536×1536 像素。在iPad2,它是768×768 像素。的一个关键因素是,
CGContextScaleCTM(上下文,比例因子,比例因子)是用来调整坐标系统,使任何绘图核心图形,,如
CGContextMoveToPoint等,就会自动工作,无论是标准分辨率的Retina分辨率。一个更值得注意的是,
UIGraphicsBeginImageContext(CGSizeMake(300,300));将创建一个300×300 像素的 Retina显示屏,而
UIGraphicsBeginImageContextWithOptions(CGSizeMake(300,300),NO,0.0);将创建600×600 像素的Retina上显示。
0.0的方法调用自动给出合适的大小为标准的显示器或Retina显示屏。
相关文章推荐
- 32.CGBitmapContextCreate 在配备Retina的设备上绘制模糊的 解决方法 iOS截屏模糊
- 解决 CGBitmapContextCreate: unsupported parameter combination 错误
- myeclipse 10 在mac retina 屏幕下显示字体模糊解决方法
- myeclipse 10 在mac retina 屏幕下显示字体模糊解决方法
- 解决 Mac OS X Retina 屏幕显示环境下 jEdit 字体模糊的方法
- QT5.3.1安装成功Failed to create OpenGL context错误解决方法
- 解决 CGBitmapContextCreate: unsupported parameter combination 错误
- MATLAB 2014a 在Mac os x yosemite 10.10 Retina显示模糊的解决的方法
- 解决myeclipse在mac中Retina屏幕中模糊的终极详细方法
- Canvas 在高清屏下绘制图片变模糊的解决方法
- cocos2d-x在IOS7下面文字显示异常的解决办法 CGBitmapContextCreate: unsupported parameter combination
- Canvas 在高清屏下绘制图片变模糊的解决方法
- CGBitmapContextCreate()的使用方法
- Oracle Linux 6.1 安装Oracle 10g ORA-27125:unable to create shared memory segment 解决方法
- genymotion 下载虚拟设备失败或中断 的解决方法
- eclipse Failed to create the part's controls 解决方法
- 删除U盘时提示无法停止‘通用卷’设备的解决方法
- iphone CGBitmapContextCreate()函数解释
- win7 下adb devices找不到设备的解决方法
- 郁闷N天了,IDFTP发生10054错误后无法继续上传文件,重新创建IDFTP后发生错误:550 cannot create file。请教解决方法