Search code examples
iosobjective-ccocoacgimage

How do I create a CGImage with RGB data?


Can anyone show me a clear example of how to use

CGImageRef CGImageCreate 
(
   size_t width,
   size_t height,
   size_t bitsPerComponent,
   size_t bitsPerPixel,
   size_t bytesPerRow,
   CGColorSpaceRef colorspace,
   CGBitmapInfo bitmapInfo,
   CGDataProviderRef provider,
   const CGFloat decode[],
   bool shouldInterpolate,
   CGColorRenderingIntent intent
);

I have a CGFloat dataBuffer [width * height * 3];

It contains all of the RGB data of the image. Essentially, it goes from pixel R (0,0), G (0,0), B(0,0), R(0,1)... to R(width, height), G(width,height), B(width,height)

I know the size of the image, width x height. How do I use the information that I have and create and CGImage??

Please help, thanks

I posted another question that encompasses the above question. It was answered correctly by nschmidt, here is the link

Converting RGB data into a bitmap in Objective-C++ Cocoa


Solution

  • I posted another question that encompasses the above question. It was answered correctly by nschmidt, here is the link

    Converting RGB data into a bitmap in Objective-C++ Cocoa