I know have many questions like this on stackoverflow
and also have the answer for it like on this link: How to convert text to Image on iOS?. But with me, I need to draw many (more than 800 image) UIImages. So that, if I do my job as follow:
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
}
My app will run so very slowly ~ app get jerky. I hear about the GPU acceleration
but don't have any experience on GPU
. How to draw image (as my function) but use the GPU
to do this?