2017-02-04 17 views
8

Bir pencerenin içinde gerçekten uzun bir sayfa var (tümünü görüntülemek için kaydırmak gerekiyor), aşağıdaki kodu kullanarak tüm pencereyi yakalamaya çalıştığımda, tam WebContent yerine sıkılmış bir görüntü alıyorum CurrentWindow içindeki ekran görüntüsü. WindowsContent içinde tüm WebContent ele geçirmek için

 const remote = require('electron').remote; 
     const win = remote.getCurrentWindow(); 
     const win_size = win.getSize(); 
     const win_height = win_size[0]; 
     const win_width = win_size[1]; 

     win.capturePage({ 
       x: 0, 
       y: 0, 
       width: win_width, 
       height: win_height 
      }, 
      (img) => { 
       remote.require('fs') 
        .writeFile(TEMP_URL, img.toPng()); 
      }); 

https://github.com/electron/electron/blob/master/docs/api/browser-window.md#wincapturepagerect-callback

Ayrıca aşağıdaki kodu denedi ancak sonuç

 const remote = require('electron').remote; 
     const webContents = remote.getCurrentWebContents(); 

     webContents.capturePage({ 
      x: 0, 
      y: 0, 
      width: 1000, 
      height: 2000 
     }, (img) => { 
      remote.require('fs') 
       .writeFile(TEMP_URL, img.toPng()); 
     }); 

capturePage yönteme geçirilen birinci amacı, bağlı olmalıdır, aynı ama olduğu ortaya çıkıyor çıktı görüntüsünün boyutu.

GeçerliWindow'daki WebContent öğesinin doğru boyutu olan win_size incelemesini yaptım. enter image description here

cevap

2
win.getSize() 

enter image description here[width, height] ile bir dizi döner. win_width değişkenini pencerenin yüksekliğine ve pencerenin genişliğine win_height atayabilirsiniz. Bu değerleri değiştirirseniz, bu sorunu çözebilir.

const win_height = win_size[1]; 
const win_width = win_size[0]; 
+0

https://github.com/electron/electron/issues/8586#event-954437220 –

+0

aksi sınırları al, bu bir hata olduğunu çıkıyor bu sana atık her durumda. –

İlgili konular