2017-02-28 8 views
0

私は、ユーザーが画面の領域を選択できるようにする(スクリーンショットをとるなど)アプリケーションを作成しようとしています。電子機器でデスクトップ画面の領域を選択

folders in home

はあっても可能ですか?

+0

コンテキストに関する情報が不十分です。画面上に選択矩形を描画したいだけですか?そして、「スクリーン」とは、エレクトロンアプリケーションのコンテキストです:メインウィンドウ?ユーザーのデスクトップ? –

+1

@NoGrabbing "スクリーンショットを取るように選択する"。 Snippingツールのように。彼はPC上の特定の場所を意味するものではありません。 – Crowes

+0

は、スクリーンショットを撮るというコンセプトのように、どこでも実行できます。 –

答えて

-1

具体的にフルスクリーンショットを撮るには、次のコードを使用してください(例:Electron Demo Appから取得)。この例では、電子アプリでscreendesktopCapturerrectangleモジュールを使用してコードをカスタマイズし、特定の画面/ディスプレイを表示したり、特定の境界ボックス(x/y座標とピクセル領域)を選択することができます。あなたがこのことについて行くことができる

const electron = require('electron') 
const desktopCapturer = electron.desktopCapturer 
const electronScreen = electron.screen 
const shell = electron.shell 

const fs = require('fs') 
const os = require('os') 
const path = require('path') 

const screenshot = document.getElementById('screen-shot') 
const screenshotMsg = document.getElementById('screenshot-path') 

screenshot.addEventListener('click', function (event) { 
    screenshotMsg.textContent = 'Gathering screens...' 
    const thumbSize = determineScreenShotSize() 
    let options = { types: ['screen'], thumbnailSize: thumbSize } 

    desktopCapturer.getSources(options, function (error, sources) { 
    if (error) return console.log(error) 

    sources.forEach(function (source) { 
     if (source.name === 'Entire screen' || source.name === 'Screen 1') { 
     const screenshotPath = path.join(os.tmpdir(), 'screenshot.png') 

     fs.writeFile(screenshotPath, source.thumbnail.toPng(), function (error) { 
      if (error) return console.log(error) 
      shell.openExternal('file://' + screenshotPath) 
      const message = `Saved screenshot to: ${screenshotPath}` 
      screenshotMsg.textContent = message 
     }) 
     } 
    }) 
    }) 
}) 

function determineScreenShotSize() { 
    const screenSize = electronScreen.getPrimaryDisplay().workAreaSize 
    const maxDimension = Math.max(screenSize.width, screenSize.height) 
    return { 
    width: maxDimension * window.devicePixelRatio, 
    height: maxDimension * window.devicePixelRatio 
    } 
} 

他の方法があります。これは彼らが何であるかの予備知識を必要とするが、DOMで

  1. 使用object.getClientRects()は、キャプチャする特定の要素を指定します。
  2. mouseClick、mouseMoveなどで、必要なものの形状を '描画'するために、イベントリスナーを追加します。このstack overflow questionには、あなたがやりたいことに合わせて適応できる回答があります。
+0

を意味しているwhtを得ると思います。一方、あなたが私の助けを借りて(質問の写真のような) –

+0

答えがunvoweredされ、downvotedされた理由を誰でも説明できるなら、それは高く評価されるでしょう。答えはOPの内容をキャプチャするOPの必要性を説明します(コメントに記載されたスクリーンショットのように)選択ボックスを描画する方法を探索します。 –

関連する問題