简体   繁体   English

将一个UIView上下文的位图内容复制到另一个UIView

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

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. 基本上,我想做的是将已经渲染的内容(使用CGContextDrawPDFPage()绘制到UIView的图形上下文中的PDF)复制到类似的UIView上,而不必重新渲染PDF。 The idea is, that I'd then be able to perform an animated transform on the UIView and later re render the PDF with more accuracy. 我的想法是,然后我可以在UIView上执行动画转换,然后再更精确地重新渲染PDF。 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. 对于两个UIView,我都使用大于屏幕的CATiledLayer,以使用户放大后更轻松地重新渲染PDF(如果有任何区别)。

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 假设您已使用类似于以下内容的代码在图形上下文中渲染了PDF页面

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 此代码会将pdfView的内容保存到UIImage

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM