【问题标题】:ipad, sdk, CGBitmapContextCreateipad, sdk, CGBitmapContextCreate
【发布时间】:2010-10-15 12:02:34
【问题描述】:

现在我正在开发一个接受 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;}

【问题讨论】:

    标签: image-processing core-graphics ipad


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      相关资源
      最近更新 更多