对于macOS Cocoa,我如何在屏幕上指定一个窗口或一个矩形来拍摄屏幕截图? [英] For macOS Cocoa, how do I specify a window or a rectangle on the screen for taking a screenshot?

查看:216
本文介绍了对于macOS Cocoa,我如何在屏幕上指定一个窗口或一个矩形来拍摄屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个用于测量图像文件的macOS应用程序,并且希望添加一项功能来捕获屏幕截图.我希望它具有一个类似于macOS应用程序预览"所具有的操作界面.

I have written a macOS app for measuring image files, and I wish to add a feature for capturing screenshots. I wish for it to have a user interface for doing it much like what the macOS app "Preview" has.

要使用其屏幕截图功能,请执行文件">获取屏幕截图",然后使用以下选项获得一个子菜单:

To use its screenshot function, one does File > Take Screenshot, and one gets a submenu with these options:

  • 从选择中...
  • 从窗口...
  • 在整个屏幕上

从选择中..."使您可以通过单击并拖动在屏幕上选择一个矩形.

"From Selection..." lets you select a rectangle on the screen by clicking and dragging.

通过从窗口...",您可以选择一个应用程序窗口.

"From Window..." lets you select an app window.

从整个屏幕"就是它的意思.

"From Entire Screen" is what it says.

我可以找到用于将屏幕快照作为图像对象获取的代码,但是我找不到用于用户界面部分(用于选择矩形或窗口的部分)的任何代码.有谁知道这是怎么做到的吗?否则,有一些执行此操作的代码.

I can find the code for getting the screenshot as an image object, but I haven't been able to find any code for the user-interface part, the part for selecting a rectangle or a window. Does anyone know how to do that? Or else have some code for doing that.

推荐答案

尝试调用 screencapture 命令行工具:

screencapture -i -c

这将运行默认的macOS界面,以选择屏幕上的区域并将捕获的图像存储在剪贴板上.使用 -Jwindow 捕获窗口:

This will run the default macOS interface for selecting a region on the screen and store the captured image on the clipboard. Use the -Jwindow to capture a window instead:

screencapture -i -c -Jwindow

或将 -i 标志替换为 -S 标志以非交互方式捕获整个屏幕:

Or replace the -i flag with the -S flag to capture the entire screen non-interactively:

screencapture -S -c -Jwindow

这篇关于对于macOS Cocoa,我如何在屏幕上指定一个窗口或一个矩形来拍摄屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆