Support scale factor to buffer APIs

This commit is contained in:
Kevin Sawicki 2017-03-06 16:19:16 -08:00
parent e4ead6d018
commit 82a81bb26e
3 changed files with 79 additions and 34 deletions

View file

@ -11,11 +11,15 @@ describe('nativeImage module', () => {
assert.equal(empty.isEmpty(), true)
assert.equal(empty.getAspectRatio(), 1)
assert.equal(empty.toDataURL(), 'data:image/png;base64,')
assert.equal(empty.toDataURL({scaleFactor: 2.0}), 'data:image/png;base64,')
assert.deepEqual(empty.getSize(), {width: 0, height: 0})
assert.deepEqual(empty.getBitmap(), [])
assert.deepEqual(empty.getBitmap({scaleFactor: 2.0}), [])
assert.deepEqual(empty.toBitmap(), [])
assert.deepEqual(empty.toBitmap({scaleFactor: 2.0}), [])
assert.deepEqual(empty.toJPEG(100), [])
assert.deepEqual(empty.toPNG(), [])
assert.deepEqual(empty.toPNG({scaleFactor: 2.0}), [])
if (process.platform === 'darwin') {
assert.deepEqual(empty.getNativeHandle(), [])
@ -98,6 +102,14 @@ describe('nativeImage module', () => {
assert.deepEqual(imageC.getSize(), {width: 538, height: 190})
assert(imageB.toBitmap().equals(imageC.toBitmap()))
})
it('supports a scale factor', () => {
const imageA = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
const imageB = nativeImage.createFromDataURL(imageA.toDataURL({scaleFactor: 1.0}))
assert.deepEqual(imageB.getSize(), {width: 538, height: 190})
const imageC = nativeImage.createFromDataURL(imageA.toDataURL({scaleFactor: 2.0}))
assert.deepEqual(imageC.getSize(), {width: 538, height: 190})
})
})
describe('toPNG()', () => {