0

Having trouble with CGBitmapContextCreate and getting:

Error: Unsupported pixel description - 1 components, 8 bits-per-component, 8 bits-per-pixel

with this code:

float *bitmap = (float*)malloc(sizeof(float) * width * height);

// fill with floats

CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
size_t bitsPerComponent = 8;
size_t bytesPerRow = sizeof(float)*width;
CGContextRef context = CGBitmapContextCreate(bitmap, width, height, bitsPerComponent, bytesPerRow, colorspace
                                             , kCGImageAlphaNone| kCGBitmapFloatComponents | kCGBitmapByteOrder32Little);

according to: http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_context/dq_context.html

It's 8 bits per pixel and 8 bits per component. Not sure why I get the error though. I've seen a few other posts here about getting this right but most deal with editing images rather than creating new ones so some of the settings can be taken from the original image.

richy
  • 2,716
  • 1
  • 33
  • 42

1 Answers1

0

If you're using float component then surely you need to say that the bits per component is the number of bits in a float:

size_t bitsPerComponent = 8 * sizeof (float);

In other words, 8 bits per pixel != 1 float per pixel, since a float is 32 bits.

  • Thanks! but now I'm just getting Unsupported pixel description - 1 components, 32 bits-per-component, 32 bits-per-pixel – richy Sep 24 '12 at 22:39