Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

monsieurpaul

macrumors regular
Original poster
Oct 8, 2009
230
0
Hello,

I am starting to be really confused with Image, ImageRep, View, GraphicsContext, etc.

On one hand, what I have found in books and blogs focuses mainly on recipes. On the other hand, I am finding the Cocoa Drawing Guide from Apple documentation really overwhelming.

Does anyone has something else to recommend ?

Thanks,
Paul
 
I was able to get an image displayed based on a bitmap my program computed. The code looked something like this (paraphrasing)...

Code:
        NSBitmapImageRep *myBitmap;
        NSImage *myImage;
        unsigned char *buff[4];
        unsigned char *pixels;

        pixels = malloc(rectSize * 4);

        for(y = 0; y < height; y++)
        {
                for(x = 0; x < width; x++)
                {
                        // do stuff
                        pixels[i++] = red;
                        pixels[i++] = green;
                        pixels[i++] = blue;
                        pixels[i++] = 255;   // Alpha channel
                }
        }

        buff[0] = pixels;

        myBitmap = [[NSBitmapImageRep alloc]
                  initWithBitmapDataPlanes:buff 
                  pixelsWide:width
                  pixelsHigh:height
                  bitsPerSample:8
                  samplesPerPixel:4
                  hasAlpha:YES
                  isPlanar:NO
                  colorSpaceName:NSCalibratedRGBColorSpace
                  bitmapFormat:0
                  bytesPerRow:(4 * width)
                  bitsPerPixel:32];

        myImage = [[NSImage alloc] init];
        [myImage addRepresentation:myBitmap];
        [display setImage: myImage];
        [myImage release];
        [myBitmap release];
}

Where "display" is an outlet to a View which contains an image.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.