开发者

modify pixels of an CGImageRef

开发者 https://www.devze.com 2022-12-19 21:54 出处:网络
I am using the following code to modify pixels of an image. The issue I have is the color of the images are icorrect.

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

精彩评论

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

关注公众号