我想裁剪包含PDF的NSImage。在打印時,我使用NSImage的drawInRect來讓它只繪製我需要的東西 - 而且這個效果很好。NSImage - 裁剪PDF後模糊
但是,現在我試圖創建一個裁剪區域的新NSImage。我打了一段時間,然後發現CocoaBuilder此代碼:
- (NSImage *) imageFromRect: (NSRect) rect
{
NSAffineTransform * xform = [NSAffineTransform transform];
// translate reference frame to map rectangle 'rect' into first quadrant
[xform translateXBy: -rect.origin.x
yBy: -rect.origin.y];
NSSize canvas_size = [xform transformSize: rect.size];
NSImage * canvas = [[NSImage alloc] initWithSize: canvas_size];
[canvas lockFocus];
[xform concat];
// Get NSImageRep of image
NSImageRep * rep = [self bestRepresentationForDevice: nil];
[rep drawAtPoint: NSZeroPoint];
[canvas unlockFocus];
return [canvas autorelease];
}
這工作,但返回的NSImage中是模糊的,不再適用於印刷。有任何想法嗎?
確保您正式發佈或autoreleasePDF和theCroppedImage。 – 2009-02-07 02:06:55