7
我通过拍摄UIView的屏幕截图来创建一个PDF,目前这款软件在iPad3上的视网膜显示效果很好,但是当在具有较低分辨率屏幕的其他设备上测试时,文本解析问题。在视网膜和非视网膜设备上的renderInContext
这里是我的代码:
//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应该强制它以2x分辨率呈现。显示正确和错误输出的图像。 –
更新我的问题 – danielbeard
是PDF的截图吗?这两幅图像大小不同,但其中一幅不是另一幅的两倍。人们看起来也不像其他人的解决方案的两倍。尝试将每个实际的'UIImage'保存到文件中,例如'[UIImagePNGRepresentation(screenShot)writeToFile:@“/ tmp/image.png”原子:NO]'。在模拟器上执行并在每次运行后将映像从'/ tmp'中复制出来。 –