[ create a new paste ] login | about

Link: http://codepad.org/OcjWSunN    [ raw code | fork ]

C, pasted on Jul 19:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  NSSize s = [image_ size];
  CGContextRef bitmapCtx = CGBitmapContextCreate(NULL/*data - pass NULL to let CG allocate the memory*/, 
                    s.width,  
                    s.height, 
                    8 /*bitsPerComponent*/, 
                    0 /*bytesPerRow - CG will calculate it for you if it's allocating the data.  This might get padded out a bit for better alignment*/, 
                    [[NSColorSpace genericRGBColorSpace] CGColorSpace], 
                    kCGBitmapByteOrder32Host|kCGImageAlphaPremultipliedFirst);
  
  [NSGraphicsContext saveGraphicsState];
  [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:bitmapCtx flipped:NO]];
  [image_ drawInRect:NSMakeRect(0,0, s.width, s.height) fromRect:NSZeroRect/*sentinel, means "the whole thing*/ operation:NSCompositeCopy fraction:1.0];
  [NSGraphicsContext restoreGraphicsState];

  CGImageRef cgImage = CGBitmapContextCreateImage(bitmapCtx);  // FIXME: leak
  CGContextRelease(bitmapCtx);

  // Create the layer that will be animated.
  CALayer* layer = [CALayer layer];
  [layer setContents:(id)cgImage];


Create a new paste based on this one


Comments: