How do you generate an RGBA image in Core Graphics?

前端 未结 3 1175
梦谈多话
梦谈多话 2021-01-12 03:35

I\'m trying to generate an RGBA8 image from text to use as an OpenGL ES 2.0 texture.

+(UIImage *)imageFromText:(NSString *)text
{
  UIFont *font = [UIFont sy         


        
3条回答
  •  伪装坚强ぢ
    2021-01-12 03:58

    I was getting the same unsupported parameter combination error even though I was using kCGImageAlphaPremultipliedLast. The issue in my case turned out to be that the width I was getting was fractional. Turning it into an integer by passing int(width) to CGBitmapContextCreate solved the problem.

    --Edit in response to Steven's comment--

    The issue with feeding in a fractional width as the second argument is not that CGBitmapContextCreate interprets it as such -- as stated, it gets casted implicitly to the argument's unsigned integer type. Rather, it produces a discrepancy in the bytes_per_row argument, since int(width * 4) is not the same as int(width) * 4. E.g. if the width is 22.5, then width gets truncated to 22, but width * 4 computes to 90, not 88.

提交回复
热议问题