【发布时间】:2012-10-24 21:41:11
【问题描述】:
我正在通过截取 UIView 的屏幕截图来创建 PDF,这目前在配备 Retina 显示屏的 iPad3 上运行良好,但在其他具有较低分辨率屏幕的设备上进行测试时,我遇到了文本分辨率问题。
这是我的代码:
//start a new page with default size and info
//this can be changed later to include extra info.
UIGraphicsBeginPDFPage();
//render the view's layer into an image context
//the last option specifies scale. If 0, it uses the devices scale.
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 2.0);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//render the screenshot into the pdf page CGContext
[screenShot drawInRect:view.bounds];
//close the pdf context (saves the pdf to the NSData object)
UIGraphicsEndPDFContext();
我也尝试将UIGraphicsBeginImageContextWithOptions 比例设置为 2.0,但这并没有改变。如何强制 iPad2 上的视图以 2 倍分辨率呈现?
预期输出:
实际输出:
【问题讨论】:
-
你有什么问题?将
UIGraphicsBeginImageContextWithOptions中的比例设置为 2 应该会强制它以 2 倍分辨率渲染。发布显示正确和错误输出的图片。 -
那些是PDF的截图吗?两张图片的大小不同,但一张不是另一张的两倍。一个看起来也不像是以另一个两倍的分辨率渲染的。尝试将每个实际的
UIImage保存到文件中,例如[UIImagePNGRepresentation(screenShot) writeToFile:@"/tmp/image.png" atomically:NO]。在模拟器上做,每次运行后从/tmp复制图像。 -
还有,文字的绘制是在哪里完成的?你能发布那个代码吗?
标签: objective-c uikit calayer quartz-core