Using the contents of an array to set individual pixels in a Quartz bitmap context

Posted by Magic Bullet Dave on Stack Overflow See other posts from Stack Overflow or by Magic Bullet Dave
Published on 2010-03-07T14:53:32Z Indexed on 2010/03/19 7:11 UTC
Read the original article Hit count: 291

Filed under:
|
|
|

I have an array that contains the RGB colour values for each pixel in a 320 x 180 display. I would like to be able to set individual pixel values in the a bitmap context of the same size offscreen then display the bitmap context in a view.

It appears that I have to create 1x1 rects and either put a stroke on them or a line of length 1 at the point in question. Is that correct? I'm looking for a very efficient way of getting the array data onto the graphics context as you can imagine this is going to be an image buffer that cycles at 25 frames per second and drawing in this way seems inefficient.

I guess the other question is should I use OPENGL ES instead?

Thoughts/best practice would be much appreciated.

Regards

Dave

OK, have come a short way, but can't make the final hurdle and I am not sure why this isn't working:

- (void) displayContentsOfArray1UsingBitmap: (CGContextRef)context
{
    long bitmapData[WIDTH * HEIGHT];

    // Build bitmap
    int i, j, h;
    for (i = 0; i < WIDTH; i++)
    {
        for (j = 0; j < HEIGHT; j++)
        {
        h = frameBuffer01[i][j];
        bitmapData[i * j] = h;
        }
}
// Blit the bitmap to the context
    CGDataProviderRef providerRef = CGDataProviderCreateWithData(NULL, bitmapData,4 * WIDTH * HEIGHT, NULL);

    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();

    CGImageRef imageRef = CGImageCreate(WIDTH, HEIGHT, 8, 32, WIDTH * 4, colorSpaceRef, kCGImageAlphaFirst, providerRef, NULL, YES, kCGRenderingIntentDefault);

    CGContextDrawImage(context, CGRectMake(0.0, HEIGHT, WIDTH, HEIGHT), imageRef);

    CGImageRelease(imageRef);
    CGColorSpaceRelease(colorSpaceRef);
    CGDataProviderRelease(providerRef);
}

© Stack Overflow or respective owner

Related posts about quartz-2d

Related posts about iphone