UIScrollView 内的 PDF 缩放
我在 2835 像素 UIScrollView 中有一个 2835 像素 PDF 文件。 为了显示 PDF,我使用 CATiledLayer。
我的问题是,当我缩小滚动视图(比例低于 1)时,PDF 质量会变得非常差。奇怪的是,当我放大滚动视图(比例大于 1)时,PDF 看起来很棒。 放大得越大(比例*10),质量就越好。
如何更改代码以使低阶和高阶质量都良好?
// Draw the CGPDFPageRef into the layer at the correct scale.
-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context
{
// First fill the background with white.
//CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
CGContextFillRect(context,CGRectMake(0, 0, 2835,1417));
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSaveGState(context);
// Flip the context so that the PDF page is rendered
// right side up.
CGContextTranslateCTM(context, 0.0, 1417);
CGContextScaleCTM(context, 1.0, -1.0);
// Scale the context so that the PDF page is rendered
// at the correct size for the zoom level.
CGContextScaleCTM(context, myScale,myScale);
CGContextDrawPDFPage(context, pdfPage);
CGContextRestoreGState(context);
}
I have a 2835 pixel PDF file inside 2835 pixel UIScrollView.
To display the PDF I use CATiledLayer.
My problem is when I zoom out the scrollView (at scale below 1) the PDF quality gets very bad. What is strange that when I zoom in the scrollView (at scale above 1) the PDF looks great.
The more I zoom in (scale*10) the better the quality.
How do I change the code so that both the downscale and upscale quality is good?
// Draw the CGPDFPageRef into the layer at the correct scale.
-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context
{
// First fill the background with white.
//CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
CGContextFillRect(context,CGRectMake(0, 0, 2835,1417));
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSaveGState(context);
// Flip the context so that the PDF page is rendered
// right side up.
CGContextTranslateCTM(context, 0.0, 1417);
CGContextScaleCTM(context, 1.0, -1.0);
// Scale the context so that the PDF page is rendered
// at the correct size for the zoom level.
CGContextScaleCTM(context, myScale,myScale);
CGContextDrawPDFPage(context, pdfPage);
CGContextRestoreGState(context);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将levelsOfDetail和levelsOfDetailBias都设置为10。这将所有缩放都转移到了升级。现在我将levelsOfDetail更改为10,将levelsOfDetailBias更改为7,一切正常。
I was setting both levelsOfDetail and levelsOfDetailBias to 10. This shifted all the zoom to upsaclaing. Now I changed levelsOfDetail to 10 and levelsOfDetailBias to 7 and all works ok.