ipad,sdk,CGBitmapContextCreate

时间:2010-10-15 12:02:35

标签: image-processing core-graphics ipad

现在我正在处理一个接受cgimageref的应用程序,处理图像的像素并返回处理过的cgimageref。为了检查它是如何工作的,我只需编写一个代码来传递cgimageref,并期望返回相同的图像而不进行处理。但问题是我没有回到确切的图像。生成的图像颜色完全改变。如果这不是正确的方法,那么请告诉我更好的方法。这是代码

  - (CGImageRef) invertImageColor :(CGImageRef) imageRef  {
     CFDataRef dataRef = CGDataProviderCopyData(CGImageGetDataProvider(imageRef));
     UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(dataRef);
     // my editing code goes here but for testing this part is omitted. i will it later             
     //when this issue is solved.
     CGContextRef ctx = CGBitmapContextCreate(m_PixelBuf,
                                         CGImageGetWidth( imageRef ),
                                         CGImageGetHeight( imageRef ),
                     CGImageGetBitsPerComponent(imageRef),
                     CGImageGetBytesPerRow( imageRef ),
                                             CGImageGetColorSpace( imageRef ),
                                             kCGImageAlphaPremultipliedFirst );

     CGImageRef newImageRef = CGBitmapContextCreateImage (ctx);
     CGContextRelease(ctx);

     return newImageRef;}

1 个答案:

答案 0 :(得分:1)

您假设输入图像的alpha预乘并存储在颜色分量之前。不要以为这个。获取图像的位图信息并将其传递给CGBitmapContextCreate

请注意,CGBitmapContext不适用于所有可能的像素格式。如果你的输入图像是CGBitmapContext不喜欢的像素格式,你只需要使用一个单独的缓冲区并将输入图像绘制到上下文中。