开发者

modify pixels of an CGImageRef

I am using the following code to modify pixels of an image. The issue I have is the color of the images are icorrect. Do you have any idea of the issue?

CGImageRef inImage = img.CGImage;

CGContextRef ctx;

    CFDataRef m_DataRef; 
    m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage)); 
    UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef); 
开发者_开发技巧//    Byte tmpByte; 
    int length = CFDataGetLength(m_DataRef); 

    for (int index = 0; index < length; index += 4) 
    { 
    //    DO Stuff 

    } 

    ctx = CGBitmapContextCreate(m_PixelBuf, 
                                CGImageGetWidth( inImage ), 
                                CGImageGetHeight( inImage ), 
                                8, 
                                CGImageGetBytesPerRow( inImage ), 
                                CGImageGetColorSpace( inImage ), 
                                kCGImageAlphaPremultipliedFirst ); 


    CGImageRef imageRef = CGBitmapContextCreateImage (ctx); 
    UIImage* rawImage = [UIImage imageWithCGImage:imageRef]; 

    CGContextRelease(ctx); 


Try using kCGImageAlphaPremultipliedLast instead of kCGImageAlphaPremultipliedFirst.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜