mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
Fix transparency in capturePage (#12561)
* Fix transparent window capture. Transparency is preserved and not converted to black pixels anymore * Add test to make sure aplha channel exists in captured image
This commit is contained in:
committed by
Cheng Zhao
parent
eca0436f58
commit
6fc819dae1
@@ -442,6 +442,29 @@ describe('BrowserWindow module', () => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('preserves transparency', (done) => {
|
||||
w.close()
|
||||
const width = 400
|
||||
const height = 400
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
width: width,
|
||||
height: height,
|
||||
transparent: true
|
||||
})
|
||||
w.loadURL('data:text/html,<html><body background-color: rgba(255,255,255,0)></body></html>')
|
||||
w.once('ready-to-show', () => {
|
||||
w.show()
|
||||
w.capturePage((image) => {
|
||||
let imgBuffer = image.toPNG()
|
||||
// Check 25th byte in the PNG
|
||||
// Values can be 0,2,3,4, or 6. We want 6, which is RGB + Alpha
|
||||
assert.equal(imgBuffer[25], 6)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('BrowserWindow.setSize(width, height)', () => {
|
||||
|
||||
Reference in New Issue
Block a user