[英]Losing NSTextEffectLetterpressStyle when drawing into 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)
這是結果:
這就是我的預期(注意白色輪廓):
CFAttributedString
和NSAttributedString
都可以將任意屬性應用於范圍。 屬性字符串類型本身並不解釋屬性。
相反,字符串繪制技術解釋了屬性。 Core Text了解與UIKit或AppKit不同的一組屬性。 此處記錄了Core Text支持的屬性集。 它沒有列出(相當於) NSTextEffectAttributeName
。
如果您使用UIGraphicsBeginImageContextWithOptions()
設置當前圖形上下文並使用NSAttributedString
繪制方法繪制,那應該可以,因為它使用UIKit進行繪圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.