开发者

Copying the bitmap contents of a UIView's context to that of another UIView

开发者 https://www.devze.com 2022-12-28 00:15 出处:网络
Basically what I want to do is copy the already rendered content (a PDF drawn into the UIView\'s graphics context using CGContextDrawPDFPage()) onto a similar UIView, without having to re render the P

Basically what I want to do is copy the already rendered content (a PDF drawn into the UIView's graphics context using CGContextDrawPDFPage()) onto a similar UIView, without having to re render the PDF. The idea is, that I'd then be able to perform an animated transform on the UIView and later re rend开发者_运维问答er the PDF with more accuracy. For both UIViews I'm using a larger-than-screen CATiledLayer to make it easier to rerender the PDF once the user zooms in, if that makes any difference.

Any tips? I'm kind of lost here.


Assuming you have rendered a PDF page in a graphics context using code similar to the following

CGPDFDocumentRef document = CGPDFDocumentCreateWithURL (filename_url);
CGPDFPageRef page = CGPDFDocumentGetPage (document, pageNumber); 
CGContextDrawPDFPage (context, page); 
CGPDFDocumentRelease (document);

This code will save the contents of pdfView to a UIImage

UIGraphicsBeginImageContext(pdfView.bounds.size);
[pdfView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *pdfViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
0

精彩评论

暂无评论...
验证码 换一张
取 消