4
NSRectFill (bounds)을 사용하여 rect를 채울 수 있다는 것을 알고 있습니다. 그러나 PDF 출력의 투명성을 유지하기 위해 NSBezierPath (rect : bounds) .fill() 만 사용하면됩니다. 그 둘의 차이점은 무엇입니까?NSRectFill과 NSBezierPath (rect)의 차이점은 무엇입니까?
func drawBackground() {
CGContextSaveGState(currentContext)
if (NSGraphicsContext.currentContextDrawingToScreen()) {
NSColor(patternImage: checkerboardImage).set()
NSRectFillUsingOperation(bounds, NSCompositingOperation.CompositeSourceOver)
}
NSColor.clearColor().setFill()
//NSRectFill(bounds) //option 1
NSBezierPath(rect: bounds).fill() // option 2
CGContextRestoreGState(currentContext)
}
extension NSImage {
static func checkerboardImageWithSize(size : CGFloat) -> NSImage {
let fullRect = NSRect(x: 0, y: 0, width: size, height: size)
let halfSize : CGFloat = size * 0.5;
let upperSquareRect = NSRect(x: 0, y: 0, width: halfSize, height: halfSize);
let bottomSquareRect = NSRect(x: halfSize, y: halfSize, width:halfSize, height: halfSize);
let image = NSImage(size: NSSize(width: size, height: size))
image.lockFocus()
NSColor.whiteColor()
NSRectFill(fullRect)
NSColor(deviceWhite: 0.0, alpha:0.1).set()
NSRectFill(upperSquareRect)
NSRectFill(bottomSquareRect)
image.unlockFocus()
return image
}
}
합성 모드가 NSCompositeCopy입니까? NSRectFillUsingOperation이 더 잘 작동 했습니까? – matt
예, 당신은 완전합니다. NSRectFillUsingOperation + CompositeCopy는 NSRectFillUsingOperation + CompositeSourceOver가 NSBezierPath + fill처럼 작동하는 동안 NSRectFill과 동일하게 수행합니다. 대답으로 써보십시오. 나는 당신에게 신용을줍니다. 감사. –
감사합니다. 다행이 다행! – matt