【发布时间】: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