0

I would like to create an image of my own. I already know its width (320*2 = 640) and height (427).

So I have some raw data :

unsigned char *rawImg = malloc(height * width * 4 *2 );

Then, I will fill it :)

Then, I have to do something like that to get a bitmap and return a (UIImage *) :

ctx = CGBitmapContextCreate(rawImg,width*2,height,8,
    ???,
    ???,
    kCGImageAlphaPremultipliedLast); 

UIImage * imgFinal = [UIImage imageWithCGImage:CGBitmapContextCreateImage(ctx)];
CGContextRelease(ctx); 



return imgFinal;

But I don't know how to create my context ctx, as you can see with the "???", even tough I read the documentation...

Please help ! Thanks :)

nax_
  • 469
  • 6
  • 16
  • So sorry, it isn't very clear but in this case width = 320, that's why I'm using "width*2", because my final image will be of width 640. – nax_ Mar 20 '11 at 18:17
  • You're right, I didn't know but I just corrected it. Thank you. – nax_ Mar 20 '11 at 21:45

2 Answers2

0

See Apple's CGBitmapContext documentation.

If you are using 4 bytes per pixel, then your bytes per row might be your half_width * 2 * 4.

Color space might be:

CGColorSpaceRef    colorSpace = CGColorSpaceCreateDeviceRGB();
hotpaw2
  • 70,107
  • 14
  • 90
  • 153
0

You can obtain the current CGContextRef using

CGContextRef context =UIGraphicsGetCurrentContext()

Chris Wagner
  • 20,773
  • 8
  • 74
  • 95