How can I write a YUV frame data into a CGContext?
Please help me,
Thanks a lot.
The general road map of what you need to do along with some pseudo-code looks like this:
First create a CG bitmap context to draw into. The list of pixel formats for is available here. As you can see on iOS your only real options are some flavor of RGB with 16 bpp or 32 bpp and an alpha channel. There are more options on Mac OS X but you will still want to use some flavor of RGB.
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef frameContext = CGBitmapContextCreate(NULL, w, h, 8, bytesPerRow, rgbColorSpace, kCGImageAlphaNoneSkipFirst);
CGColorSpaceRelease(rgbColorSpace);
void * data = CGBitmapContextGetData(frameContext);
Convert your YUV frame data into RGB and write the RGB data into the data buffer for the CG bitmap context. You can get formulas for how to do this on the Wikipedia page for YUV.
Convert the CG bitmap context into a CG image.
CGImageRef frameImage = CGBitmapContextCreateImage(frameContext);
Draw the CG image to the CG context.
CGContextDrawImage(myCGContext, myCGRect, frameImage);