开发者

Getting a CGImageRef out of a PDFDocument

I have a PDFDocument (made up of PDFPages ofcourse) and I need a CGImageRef to stick into my IKImageView.

Currently, I get the datarepresentation from the PDFPage, put it into an NSImage, then get the TIFFRepresentation of the NSI开发者_运维问答mage, put it into a CGImageSource, and then get the CGImage out of the source.

That seemsneedlessly complicated, going through two NSData steps...

However, when I try to put the PDF data directly into the CGImageSource, even though that APPEARS to work, when I get the CGImage out, it is always NULL. is there something specific I should be doing to get this to work?


In Snow Leopard there is a method -[NSImage CGImageForProposedRect:context:hints:]. Or you could draw the page into a CGBitmapContext and use CGBitmapContextCreateImage.


Look at the CreatePDFPageImage function in my CGPDFAdditions code. I think that's exactly what you need.


Try feeding the data for the PDF document (as opposed to a single page) into the CGImageSource. Images from the source should correspond to pages in the document.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜