1
我渲染PDF用下面的代碼作爲測試:CoreGraphics中:無法呈現彩色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;
}
我希望框是青色,但輸出爲黑色。