I create NSBitmapImageRep witch I fill with glReadPixels information. It looks like this:
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:width pixelsHigh:height bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:3 * width bitsPerPixel:0];
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, [imageRep bitmapData]);
and later turn it to NSData and write to file. But I get flipped upside down image. How can I fix it?
Draw into a flipped
NSImage. This will draw the upsidedown image to the correct orientation. You then get the tiff representation of theNSImagewhich you can change to other image types using anotherNSBitmapImageRepwithimageRepWithData:. Use the new image representation to make a newNSDataobject usingrepresentationUsingType:properties:and save the newNSDataobject to file.