开发者

The color of video is wrong when made from UIImage of the PNG files

I am taking a UIImage from Png file and feed it to the videoWriter.

avAdaptor appendPixelBuffer:pixelBuffer

When the end result video comes out, it seems开发者_开发百科 to lacking the one color, missing the yellow color or something.

I take alook of the function that made the pixelbuffer out of the UIImage

CVPixelBufferCreateWithBytes(NULL,
                             myWidth,
                             myHeight,
                             kCVPixelFormatType_32BGRA, 
                             (void*)CFDataGetBytePtr(image), 
                             CGImageGetBytesPerRow(cgImage), 
                             NULL, 
                             0,
                             NULL, 
                             &pixelBuffer);

I also try the kCVPixelFormatType_32AGRB and others, it didn't help.

any thoughts?


Please verify if your PNG image is with or without transparency element. If your PNG image doesn't contain transparency then it's 24-bit and not 32-bit per pixel.

Also, have you tried kCVPixelFormatType_32RGBA ?


Maybe the image sizes do not fit together.

Your input image should have the same width and height like the video output. If "myWidth" or "myHeight" is different (i.e. different aspect ratio) to the size of the image, one byte may be lost at the end of the line, which could lead to color shifting. kCVPixelFormatType_32BGRA seems to be the preferred (fastest) pixel format, so this should be okay.

There is no yellow color in RGB colorspace. This means yellow is only the >red< and >green< components. It seems that >blue< is missing.

I assume you are using a CFDataRef (maybe NSData) for the image. If it is an NSData object you can print the bytes to the debug console using

NSLog(@"data: %@", image); 

This will print a hex dump to the console. Here you can see if you have alpha and what kind of byte order your png is alike. If your image has alpha, every fourth byte should be the same number.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜