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
The color space you specify during creation wouldn't cause an error like that.
The reason you're getting that error is that you've specified 8 bits per component, presumably 4 color components in the 4*size.width
value you passed in for bytesPerRow
, yet a bitmapInfo
parameter of kCGImageAlphaNone
. kCGImageAlphaNone
means only RGB
, not RGBA
. If you want RGBA
, you should most likely specify kCGImageAlphaLast
kCGImageAlphaPremultipliedLast
.
[EDIT] sorry. I should have said kCGImageAlphaPremultipliedLast
, not kCGImageAlphaLast
.
So, something like this:
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
CGContextRef contextRef = CGBitmapContextCreate(NULL,
size.width,
size.height,
8,
4 * size.width,
colorSpace,
kCGImageAlphaPremultipliedLast);