10 NSData* data = [NSData dataWithBytes:pngData.data() length:pngData.size()];
11 NSImage* image = [[NSImage alloc] initWithData:data];
13 NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
14 [pasteboard clearContents];
15 [pasteboard writeObjects:@[ image ]];
19 NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
20 NSArray* classArray = [NSArray arrayWithObject:[NSImage
class]];
21 NSDictionary* options = [NSDictionary dictionary];
23 NSImage* image = [pasteboard readObjectsForClasses:classArray options:options].firstObject;
30 CGImageRef cgImage = [image CGImageForProposedRect:nil context:nil hints:nil];
31 width = (int)CGImageGetWidth(cgImage);
32 height = (int)CGImageGetHeight(cgImage);
34 size_t bytesPerRow = 4 * width;
35 size_t totalBytes = bytesPerRow * height;
36 pixel_data.resize(totalBytes);
38 CGContextRef context = CGBitmapContextCreate(
39 pixel_data.data(), width, height, 8, bytesPerRow, CGColorSpaceCreateDeviceRGB(),
40 kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
41 CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
42 CGContextRelease(context);
void CopyImageToClipboard(const std::vector< uint8_t > &data)
void GetImageFromClipboard(std::vector< uint8_t > &data, int &width, int &height)