【发布时间】:2017-02-10 08:40:12
【问题描述】:
我知道在stackoverflow 上有很多这样的问题,并且在这个链接上也有答案:How to convert text to Image on iOS?。但对我来说,我需要绘制许多(超过 800 张图像)UIImages。因此,如果我按以下方式工作:
func createImage(text: String, size: CGSize) -> UIImage {
let data = text.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)
let drawText = NSString(data: data!, encoding: NSUTF8StringEncoding)
let textFontAttributes = [
NSFontAttributeName: UIFont(name: "Helvetica Bold", size: 15)!,
NSForegroundColorAttributeName: UIColor.redColor(),
]
UIGraphicsBeginImageContextWithOptions(size, false, 0)
drawText?.drawInRect(CGRectMake(0, 0, size.width, size.height), withAttributes: textFontAttributes)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
我的应用会运行得很慢 ~ 应用会生涩。我听说过GPU acceleration,但对GPU 没有任何经验。如何绘制图像(作为我的功能)但使用GPU 来执行此操作?
【问题讨论】:
标签: ios objective-c swift uiimage cpu