Какао: сбой при преобразовании CGImage в PDF
У меня есть 64-битное приложение для рисования на основе какао. Я хочу получить PDF-представление текущего контекста в классе, используя Cocoa Drawing.
Метод в классе, который использует Какао Рисование:
- (NSData*) pdfData
{
...
NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:pixelsAcross
pixelsHigh:pixelsDown
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:0
bitsPerPixel:0];
NSGraphicsContext* context = [NSGraphicsContext graphicsContextWithBitmapImageRep:rep];
[context setImageInterpolation:NSImageInterpolationHigh];
[context setShouldAntialias:YES];
NSGraphicsContext *nsgc = [NSGraphicsContext graphicsContextWithGraphicsPort:[context graphicsPort] flipped:YES];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:nsgc];
//custom drawing at the context
[self drawRect:fr];
[NSGraphicsContext restoreGraphicsState];
CGImageRef image = CGBitmapContextCreateImage([context graphicsPort]);
MyPDFView* pdfView = [[MyPDFView alloc] initWithFrame:fr imageRef:image];
NSData* pdfData = [pdfView dataWithPDFInsideRect:fr];
return pdfData;
}
MyPDFView: NSView
...
- (void) drawRect:(NSRect) rect
{
[[NSColor clearColor] set];
NSRectFill([self bounds]);
CGContextRef contextRef = [[NSGraphicsContext currentContext] graphicsPort];
if (_imageRef)
CGContextDrawImage(contextRef, CGRectMake([self bounds].origin.x, [self bounds].origin.y, NSWidth([self bounds]), NSHeight([self bounds])), _imageRef);
}
Эта проблема. Это прекрасно работает для меня, но я получаю отчеты о сбоях от некоторых из моих пользователей, и я не могу воспроизвести это сам.
0 CoreGraphics 0x00007fff857c2163 decode_byte_8bpc_3a + 619
1 CoreGraphics 0x00007fff857bfdbc decode_data + 13562
2 CoreGraphics 0x00007fff857bbe8f img_decode_read + 380
3 CoreGraphics 0x00007fff857bba07 img_alphamerge_read + 555
4 CoreGraphics 0x00007fff85985b82 CGSImageStreamRead + 197
5 libPDFRIP.A.dylib 0x00000001071e08a7 PDFImageEmitDefinition + 1198
6 CoreFoundation 0x00007fff848c0642 __CFSetApplyFunction_block_invoke + 17
7 CoreFoundation 0x00007fff848a50b0 CFBasicHashApply + 127
8 CoreFoundation 0x00007fff848c05ea CFSetApplyFunction + 185
9 libPDFRIP.A.dylib 0x00000001071e1375 PDFImageSetEmitDefinitions + 54
10 libPDFRIP.A.dylib 0x00000001071da917 emit_page_resources(PDFDocument*) + 88
11 libPDFRIP.A.dylib 0x00000001071da89d PDFDocumentEndPage + 72
12 libPDFRIP.A.dylib 0x00000001071d945b pdf_EndPage + 16
13 AppKit 0x00007fff873dffca -[NSView(NSPrintingInternal) _renderCurrentPageForPrintOperation:] + 527
14 AppKit 0x00007fff87957992 -[NSView(NSPrintingInternal) _copyForCurrentOperation] + 103
15 AppKit 0x00007fff87784ebd -[NSConcretePrintOperation _renderView] + 177
16 AppKit 0x00007fff87785657 -[NSConcretePrintOperation runOperation] + 677
17 AppKit 0x00007fff879577a8 -[NSView(NSPrinting1) dataWithPDFInsideRect:] + 113
18 MyDrawingKit 0x00000001068b9daf -[MyDrawing pdfData] (MyDrawing.m:2196)
Я погуглил о сбоях в этом системном методе decode_byte_8bpc_3a, и есть советы по изменению профиля монитора на "Общий профиль RGB", чтобы избежать таких сбоев, но нет объяснения, как этого избежать в коде.
Что может быть причиной такого сбоя и как его избежать?