2017-04-12 3 views
1

をレンダリングすることはできません。CoreGraphics:私はテストとして、次のコードでPDFレンダリングしていますカラーPDF

#import <Foundation/Foundation.h> 
#import <CoreGraphics/CoreGraphics.h> 

int main(int argc, const char * argv[]) { 
    @autoreleasepool { 

    NSURL* theFile = [NSURL fileURLWithPath:@"test.pdf"]; 

    CGContextRef pdfContext = CGPDFContextCreateWithURL((CFURLRef) theFile, nil, nil); 

    CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); 
    assert(CGColorSpaceGetNumberOfComponents(rgb) == 3); 
    CGContextSetFillColorSpace(pdfContext,rgb); 
    CGContextSetStrokeColorSpace(pdfContext, rgb); 
    CGColorSpaceRelease(rgb); 

    CGPDFContextBeginPage(pdfContext, nil); 

    CGFloat rgba[4] = {0.0,1.0,1.0,1.0}; 
    CGContextSetFillColor(pdfContext, rgba); 
    CGContextFillRect(pdfContext, CGRectMake(100, 100, 100, 100)); 

    CGPDFContextEndPage (pdfContext); 
    CGContextRelease (pdfContext); 
    } 
    return 0; 
} 

を私はボックスは、シアンであることを期待するが、出力は黒です。

答えて

0

CGPDFContextBeginPage(pdfContext, nil);を色空間の上に移動します。私はあなたのページを開始していないので、あなたの色空間の変更は静かに破棄されていると思います。ありがとう、CoreGraphics!

関連する問題