在绘制到CGBitmapContext时丢失NSTextEffectLetterpressStyle

时间:2015-02-19 06:21:09

标签: ios swift nsattributedstring ciimage cgbitmapcontext

我在纯色背景上绘制文字,当它出现时,应用于属性字符串的NSTextEffectLetterpressStyle效果未显示 - 您只能看到文字颜色而不是附加白色提供所需外观的轮廓。它看起来基本上与我没有应用凸版印刷效果完全相同。为什么这样,我怎样才能正确地绘制凸版文字效果?

let bitmapContext = CGBitmapContextCreate(nil, UInt(imageRect.width), UInt(imageRect.height), UInt(8), UInt(imageRect.width * 16), CGColorSpaceCreateDeviceRGB(), CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue))

CGContextSetFillColorWithColor(bitmapContext, UIColor.blackColor().CGColor)
let fullBox = CGRectMake(0, 0, imageRect.width, imageRect.height)
CGContextAddRect(bitmapContext, fullBox)
CGContextFillPath(bitmapContext)

CGContextSetTextDrawingMode(bitmapContext, kCGTextFill)
CGContextSetTextPosition(bitmapContext, drawPoint.x, drawPoint.y)
let coloredAttributedString = NSAttributedString(string: "20", attributes:[NSFontAttributeName: myFont, NSForegroundColorAttributeName: textColor, NSTextEffectAttributeName: NSTextEffectLetterpressStyle])
let displayLineTextColored = CTLineCreateWithAttributedString(coloredAttributedString)
CTLineDraw(displayLineTextColored, bitmapContext)

let cgImage = CGBitmapContextCreateImage(bitmapContext)
var myImage = CIImage(CGImage: dateStampCGImage)

这是结果:
enter image description here

这就是我的预期(注意白色轮廓):
enter image description here

0 个答案:

没有答案