Có thể của nó. Chức năng này chụp tất cả các ảnh chụp màn hình được kết nối và ghi vào đường dẫn được chỉ định dưới dạng tệp jpg. Tạo tên tệp dưới dạng dấu thời gian unix.
func TakeScreensShots(folderName: String){
var displayCount: UInt32 = 0;
var result = CGGetActiveDisplayList(0, nil, &displayCount)
if (result != CGError.success) {
print("error: \(result)")
return
}
let allocated = Int(displayCount)
let activeDisplays = UnsafeMutablePointer<CGDirectDisplayID>.allocate(capacity: allocated)
result = CGGetActiveDisplayList(displayCount, activeDisplays, &displayCount)
if (result != CGError.success) {
print("error: \(result)")
return
}
for i in 1...displayCount {
let unixTimestamp = CreateTimeStamp()
let fileUrl = URL(fileURLWithPath: folderName + "\(unixTimestamp)" + "_" + "\(i)" + ".jpg", isDirectory: true)
let screenShot:CGImage = CGDisplayCreateImage(activeDisplays[Int(i-1)])!
let bitmapRep = NSBitmapImageRep(cgImage: screenShot)
let jpegData = bitmapRep.representation(using: NSBitmapImageFileType.JPEG, properties: [:])!
do {
try jpegData.write(to: fileUrl, options: .atomic)
}
catch {print("error: \(error)")}
}
}
func CreateTimeStamp() -> Int32
{
return Int32(Date().timeIntervalSince1970)
}
Nguồn
2016-11-29 11:01:46
vì lý do bảo mật và quyền riêng tư rất đáng kể từ cả nhà phát triển và quan điểm của người dùng. – holex
Có, tôi hiểu nhưng tôi không có ý định phát hành phần mềm này, nó phù hợp hơn cho việc học tập và các mục đích phổ biến trong nhà và tôi sẽ ổn nếu một cửa sổ "chấp nhận ảnh chụp màn hình" nhỏ xuất hiện. – user6879072
'NSTask' -' screencapture' – vadian