Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li>Create a new "Cocoa Application" (if you don't know how to create a cocoa application go to <a href="http://cocoadevcentral.com/d/learn_cocoa/" rel="nofollow" title="Cocoa Dev Central">Cocoa Dev Center</a>)</li> <li>Subclass NSView (if you don't know how to subclass a view <a href="http://developer.apple.com/library/ios/documentation/IDEs/Conceptual/xcode_quick_start/Xcode_Quick_Start_Guide.pdf" rel="nofollow">read section "Create the NSView Subclass"</a>)</li> <li>Set your NSWindow to size 400x400 on interface builder</li> <li><p>Use this code in your NSView</p> <pre><code>#import "MyView.h" @implementation MyView #define WIDTH 400 #define HEIGHT 400 #define SIZE (WIDTH*HEIGHT) #define BYTES_PER_PIXEL 2 #define BITS_PER_COMPONENT 5 #define BITS_PER_PIXEL 16 - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code here. } return self; } - (void)drawRect:(NSRect)dirtyRect { // Get current context CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; // Colorspace RGB CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); // Pixel Matrix allocation unsigned short *pixels = calloc(SIZE, sizeof(unsigned short)); // Random pixels will give you a non-organized RAINBOW for (int i = 0; i &lt; WIDTH; i++) { for (int j = 0; j &lt; HEIGHT; j++) { pixels[i+ j*HEIGHT] = arc4random() % USHRT_MAX; } } // Provider CGDataProviderRef provider = CGDataProviderCreateWithData(nil, pixels, SIZE, nil); // CGImage CGImageRef image = CGImageCreate(WIDTH, HEIGHT, BITS_PER_COMPONENT, BITS_PER_PIXEL, BYTES_PER_PIXEL*WIDTH, colorSpace, kCGImageAlphaNoneSkipFirst, // xRRRRRGGGGGBBBBB - 16-bits, first bit is ignored! provider, nil, //No decode NO, //No interpolation kCGRenderingIntentDefault); // Default rendering // Draw CGContextDrawImage(context, self.bounds, image); // Once everything is written on screen we can release everything CGImageRelease(image); CGColorSpaceRelease(colorSpace); CGDataProviderRelease(provider); } @end </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload