I'm trying to draw an image from an array of data. Simplified the code looks like<BR><BR><pre class="ip-ubbcode-code-pre">
void drawDataInRect(CGContextRef context, CGRect frame) {
size_t width = 100;
size_t height = 100;
CGFloat bitMapData[width*height*4];
for (size_t i = 0, e = height*width*4; i < e
{
// This would be replaced with the actual data converted to RGB components.
bitMapData[i++] = 1.0f;
bitMapData[i++] = 0.0f;
bitMapData[i++] = 0.0f;
bitMapData[i++] = 1.0f;
}
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
CGContextRef bitMapContext = CGBitmapContextCreate(bitMapData, width, height, 16, 4*width, colorSpace, kCGImageAlphaLast | kCGBitmapFloatComponents);
CGColorSpaceRelease(colorSpace);
CGImageRef bitMapImage = CGBitmapContextCreateImage(bitMapContext);
CGContextDrawImage(context, frame, bitMapImage);
CGImageRelease(bitMapImage);
CGContextRelease(bitMapContext);
}
</pre> <BR><BR>How this just produces a blank image. What is the easiest way to draw an array of pixel values?
void drawDataInRect(CGContextRef context, CGRect frame) {
size_t width = 100;
size_t height = 100;
CGFloat bitMapData[width*height*4];
for (size_t i = 0, e = height*width*4; i < e
// This would be replaced with the actual data converted to RGB components.
bitMapData[i++] = 1.0f;
bitMapData[i++] = 0.0f;
bitMapData[i++] = 0.0f;
bitMapData[i++] = 1.0f;
}
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
CGContextRef bitMapContext = CGBitmapContextCreate(bitMapData, width, height, 16, 4*width, colorSpace, kCGImageAlphaLast | kCGBitmapFloatComponents);
CGColorSpaceRelease(colorSpace);
CGImageRef bitMapImage = CGBitmapContextCreateImage(bitMapContext);
CGContextDrawImage(context, frame, bitMapImage);
CGImageRelease(bitMapImage);
CGContextRelease(bitMapContext);
}
</pre> <BR><BR>How this just produces a blank image. What is the easiest way to draw an array of pixel values?