Je migre le code Cocoa-Java vers Cocoa + JNI car Cocoa-Java est obsolète. Le code imprime une image stockée dans un fichier. Le nouveau code de cacao est essentiellement:Impression d'un 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];
}
exécution de ce code se bloque finalement avec:
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
Pourquoi? Comment puis-je simplement imprimer une image stockée dans un fichier?
Ne pas oublier de libérer ce que vous avez allocked. http://developer.apple.com/mac/library/documentation/General/Conceptual/DevPedia-CocoaCore/MemoryManagement.html –
Quelle version de la plate-forme OS êtes-vous? Est-ce qu'il se comporte de la même manière partout où vous l'essayez? –
@Quinn: Plate-forme = Leopard. Est-ce qu'il se comporte de la même manière partout? Inconnu: Je n'ai que mon propre ordinateur pour l'essayer. –