RGB colors are getting displayed as BRG after rendering on MAC OS X

285 views Asked by At

When we are trying to render the image the image is getting displayed where the Red and Blue values are getting interchanged,

      {

    colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);

        ...

    cgctx = CGBitmapContextCreate (bitmapData,
                                pixelsWide,
                                pixelsHigh,
                                8,      // bits per component
                                bitmapBytesPerRow,
                                colorSpace,
                                kCGImageAlphaPremultipliedLast);

 }

if i use kCGImageAlphaPremultipliedFirst instead of kCGImageAlphaPremultipliedLast the image different altogether and now i find the Green and Red and getting a bit interchanged.

Please Advice.

1

There are 1 answers

0
Venkat On BEST ANSWER

The above problem of color distortion was happening due to the way pixels have been read from the Bitmap context, it is better advised to overcome this situations by making the following changes,

#if __BIG_ENDIAN__ bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big; #else bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little; #endif