Electron截屏功能


# Electron截屏功能
window下增加該功能,可以調用三方的exe文件然后通過node.js的原生模塊,execFile啟動該exe文件。
mac下則可以通過screencapture 來調用系統的截屏功能來實現

 

globalShortcut.register('CommandOrControl+Alt+Z', function () {
  if (process.platform === 'darwin') {
    handleScreenShots()
  } else {
    screenWindow()
  }
})
function screenWindow() {
  console.log('__dirname', __dirname)
  let url = path.resolve(__dirname, '../../qq/PrScrn.exe')
  // let url = path.resolve(__dirname, '../extraResources/PrintScr.exe')

  if (isDevelopment && !process.env.IS_TEST) {
    // 生產環境
    url = path.join(__dirname, '/qq/PrintScr.exe')
  }
  console.log(url + '截圖工具路徑')
  let screenWindow = execFile(url)
  screenWindow.on('exit', (code) => {
    mainWindow.restore()
    if (code) console.log(code)
  })
}
function handleScreenShots() {
  exec(`screencapture -i -U -c`, (error, stdout, stderr) => {
    console.log('308', error)
  })
}

screencapture

-c 強制截圖保存到剪貼板而不是文件中
-C 截圖時保留光標(只在非交互模式下有效)
-d display errors to the user graphically(不知道啥意思)
-i 交互模式截取屏幕。可以是選區或者是窗口。按下空格可切換截屏模式
-m 只截取主顯示器(-i模式下無效)
-M 截圖完畢后,會打開郵件客戶端,圖片就躺在郵件正文中
-o 在窗口模式下,不截取窗口的陰影
-P 截圖完畢后,在圖片預覽中打開
-s 只允許鼠標選擇模式
-S 窗口模式下,截取屏幕而不是窗口
-t png 指定圖片格式,模式是png。可選的有pdf, jpg, tiff等
-T 延時截取,默認為5秒。
-w 只允許窗口截取模式
-W 開始交互截取模式,默認為窗口模式(只是默認模式與-i不同)
-x 不播放聲效
-a do not include windows attached to selected windows(不懂)
-r 不向圖片中加入dpi信息
-l<windowid> 抓取指定windowid的窗口截圖
-R<x,y,w,h> 抓取指定區域的截圖
-B<bundleid> 截圖輸出會被bundleid指出的程序打開
-U 打開截屏操作版
需要注意的是,調用這個功能的時候需要系統授權,否則截屏時,將會報錯,不能從window創建圖片。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM