【问题标题】:Get pixel from the screen (screenshot) in Max OSX [duplicate]在 Max OSX 中从屏幕(屏幕截图)获取像素 [重复]
【发布时间】:2013-06-24 11:03:36
【问题描述】:

我一直试图从 MacOSX 10.8.4 中的 C++ 程序中获取屏幕截图,但这是不可能的。我什至无法获得一个像素。有没有可能?

有人可以帮助我吗?或者至少给我一些线索或链接。

【问题讨论】:

  • 这当然是可能的——例如,参见"Son of Grab" sample code。如果您告诉我们您的尝试,我们可以为您提供更具体的帮助。

标签: c++ macos opengl screenshot


【解决方案1】:
void captureScreen(){
    CGImageRef image_ref = CGDisplayCreateImage(CGMainDisplayID()); 
    CGDataProviderRef provider = CGImageGetDataProvider(image_ref);
    CFDataRef dataref = CGDataProviderCopyData(provider);
    size_t width, height;    width = CGImageGetWidth(image_ref);
    height = CGImageGetHeight(image_ref); 
    size_t bpp = CGImageGetBitsPerPixel(image_ref) / 8;
    uint8 *pixels = malloc(width * height * bpp);
    memcpy(pixels, CFDataGetBytePtr(dataref), width * height * bpp);
    CFRelease(dataref); 
   CGImageRelease(image_ref); 
   FILE *stream = fopen("/Users/robert/Desktop/screencap.raw", "w+");
   fwrite(pixels, bpp, width * height, stream);
   fclose(stream); 
   free(pixels);
}

参考https://gist.github.com/robert-wallis/5063309

【讨论】:

  • 谢谢!!!这就是我想要的。但是当我用 Photoshop 2 打开图像时,RGB 通道被置换了。有什么线索吗?
【解决方案2】:

如果您只想抓取窗口的图像,请尝试按按键顺序⌘+shift+3整个屏幕的快照,并将生成的图像放在桌面上。

将 3 替换为 4 将允许您以交互方式选择屏幕区域。

最后,按⌘+shift+4,然后空格将允许您选择一个窗口捕获。

page 很好地描述了许多在屏幕上捕获内容的方法。

【讨论】:

  • 叹息;英语的歧义。好吧,希望这对某人有用。
  • 这与 C++ 或 OpenGL 无关。
猜你喜欢
  • 2014-02-01
  • 2012-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-12
  • 1970-01-01
  • 2014-08-28
相关资源
最近更新 更多