java pdf绘图,模糊PDF绘图与CATiledLayer相比

在我的应用程序中,我正在创建一个PDF阅读器 . 为了满足性能,我以默认比例绘制视图 . 此视图不是基于CATiledLayer的 . 当用户放大一点时,我用CATiledLayer覆盖这个视图,在正常使用情况下,它提供更清晰的图像和低内存使用 .

现在问题是在默认状态下(当显示CALayer视图时)图像出现有点模糊 . 当我尝试放大一点点并且CATiledLayer开始时,相同的文本和一切都变得尖锐 .

这是CATiledLayer视图的代码(显示清晰的图像和文本):

- (void)drawLayer:(CATiledLayer *)layer inContext:(CGContextRef)context{

CGPDFPageRef drawPDFPageRef = NULL;

CGPDFDocumentRef drawPDFDocRef = NULL;

@synchronized(self) {

if (_PDFDocRef==nil) {

NSLog(@"PDF NIL");

_PDFDocRef = [SharedPDFDocRef sharedInstanceForUrl:_fileURL andPhrase:_password];

_PDFPageRef = CGPDFDocumentGetPage(_PDFDocRef, _page);

}

drawPDFDocRef = _PDFDocRef;

drawPDFPageRef = _PDFPageRef;

}

if (drawPDFPageRef != NULL) {

CGContextTranslateCTM(context, 0.0f, self.bounds.size.height);

CGContextScaleCTM(context, 1.0f, -1.0f);

CGAffineTransform transform =

CGPDFPageGetDrawingTransform(drawPDFPageRef, kCGPDFCropBox, layer.bounds, 0, true);

CGContextConcatCTM(context, transform);

CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);

CGContextSetInterpolationQuality(context, kCGInterpolationDefault);

CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f);

CGContextFillRect(context, CGPDFPageGetBoxRect(drawPDFPageRef, kCGPDFBleedBox));

CGContextDrawPDFPage(context, drawPDFPageRef);

}

//CGPDFPageRelease(drawPDFPageRef); CGPDFDocumentRelease(drawPDFDocRef);

}

这是普通视图的代码(显示正常,但图像与CATiledLayer的质量不同):

- (void) drawRect:(CGRect)rect {

[super drawRect:rect];

CGPDFPageRef drawPDFPageRef = NULL;

CGPDFDocumentRef drawPDFDocRef = NULL;

@synchronized(self) {

drawPDFDocRef = CGPDFDocumentRetain(_PDFDocRef);

drawPDFPageRef = CGPDFPageRetain(_PDFPageRef);

}

// get the page reference

CGPDFPageRef page = drawPDFPageRef;

CGContextRef context = UIGraphicsGetCurrentContext();

// white background

// transformation/-lation

CGContextTranslateCTM(context, 0.0, self.bounds.size.height);

CGContextScaleCTM(context, 1.00f, -1.00f);

CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(page,

kCGPDFCropBox, self.bounds, 0, true));

CGContextSetInterpolationQuality(context, kCGInterpolationDefault);

CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);

CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f);

CGContextFillRect(context, CGPDFPageGetBoxRect(drawPDFPageRef, kCGPDFBleedBox));

CGContextDrawPDFPage(context, page);

CGPDFPageRelease(drawPDFPageRef);

CGPDFDocumentRelease(drawPDFDocRef);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值