如何将QLThumbnailImageCreate与CGPDFPageRef一起使用而不是CFURLRef

时间:2017-03-25 23:58:59

标签: pdf thumbnails nsimage

QLThumbnailImageCreate需要CFURLRef作为参数。有没有办法为CGPDFPageRef编写CFURLRef?我可以将CGPDFPageRef写入文件,然后使用该URL。它很难看,但会起作用。还有更好的方法吗?

编辑:
在这里我填写一个阵列(repArray)与在BITMAP环境中创建的页面图像:

sum2017 m n = sum [(m+μ)^n | μ<-[m..n]]

...

在这里我将图像视为一个长期的图像:

    CGContextRef pdfContext = MyCreateBitmapContext(width,height);  
    CGPDFPageRef pageRef = CGPDFDocumentGetPage (myDocument, index);
    NSImage* anImage;
    @try
    {
        CGContextDrawPDFPage (pdfContext,pageRef );
        CGImageRef ref = (CGBitmapContextCreateImage (pdfContext));
        anImage = [[NSImage alloc]initWithCGImage:ref size:NSZeroSize];

        [repArray addObject:anImage];
    }

在这里,我使用APPLE代码创建一个CGContextRef:

    NSImage* outImage = [[NSImage alloc]initWithSize:NSMakeSize(pageSize.width,(pageSize.height +    10)*numberOfPages)];
    [outImage lockFocus];
    NSRect sourceRect = NSMakeRect(0, 0, pageSize.width, pageSize.height);
    NSImage* pageImage;
    NSInteger maxH = (pageSize.height + 10)*numberOfPages;
    NSInteger unitH = pageSize.height + 10;
    for (NSInteger index = 0; index < numberOfPages; index++)
    {
        pageImage = [repArray objectAtIndex:index];
        NSPoint pt = NSMakePoint(0, maxH - (index + 1) * unitH);
        [pageImage drawAtPoint:pt fromRect:sourceRect operation:NSCompositingOperationSourceOver fraction:1.0];
    }
    [outImage unlockFocus];
    return outImage;

由于

0 个答案:

没有答案