Я переношу код Cocoa-Java в Cocoa + JNI, так как Cocoa-Java устарел. Код печатает изображение, хранящееся в файле. Новый код какао в основном:Печать NSImage
NSImage *image = [[NSImage alloc] initWithContentsOfFile:spoolFile];
if ([image isValid]) {
NSImageView *view = [[NSImageView alloc] init];
[view setImage:image];
[view setImageScaling:NSScaleProportionally];
NSPoint p;
NSSize s;
p.x = static_cast<float>(boundsX);
p.y = static_cast<float>(boundsY);
[view setBoundsOrigin:p];
s.width = static_cast<float>(boundsWidth);
s.height = static_cast<float>(boundsHeight);
[view setBoundsSize:s];
NSPrintInfo *info = [NSPrintInfo sharedPrintInfo];
[info setHorizontalPagination:NSClipPagination];
[info setVerticalPagination:NSClipPagination];
[info setHorizontallyCentered:NO];
[info setVerticallyCentered:NO];
p.x = static_cast<float>(boundsX);
p.y = static_cast<float>([info paperSize].height - boundsHeight - boundsY);
[view translateOriginToPoint:p];
NSPrintOperation *printOp =
[NSPrintOperation printOperationWithView:view printInfo:info];
[printOp setShowsPrintPanel:NO];
[printOp runOperation];
}
Выполнение этого кода в конце концов падает с:
Thread 0 Crashed:
0 com.apple.AppKit 0x9484ac75 -[NSConcretePrintOperation(NSInternal) _tryToSetCurrentPageNumber:] + 345
1 com.apple.AppKit 0x948d88cf -[NSView(NSPrintingInternal) _printForCurrentOperation] + 524
2 com.apple.AppKit 0x948d85c5 -[NSConcretePrintOperation _renderView] + 358
3 com.apple.AppKit 0x9491f0c0 -[NSConcretePrintOperation runOperation] + 362
Почему? Как я могу просто распечатать изображение, которое хранится в файле?
Не забудьте освободить то, что вы положили. http://developer.apple.com/mac/library/documentation/General/Conceptual/DevPedia-CocoaCore/MemoryManagement.html –
В какой версии платформы ОС вы используете? Ведет ли он себя одинаково везде, где вы его пытаетесь? –
@Quinn: Платформа = леопард. Ведет ли он себя одинаково повсюду? Неизвестно: у меня есть только мой компьютер, чтобы попробовать. –