views:

75

answers:

1

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);
}
+1  A: 

Read the documentation for CGImageCreate(). Basically, you have to create a CGDataProvider from your pixel array (using CGDataProviderCreateDirect()), then create a CGImage with this data provider as a source. You can then draw the image into any context. It's a bit tedious to get this right because these functions expect a lot of arguments, but the documentation is quite good.

Ole Begemann
Cheers Ole, will give it a go. Dave.
Magic Bullet Dave
Hi Ole, sorry to bother you, but any ideas what is wrong with my code above?Cheers Dave.
Magic Bullet Dave