diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index b666f86ba3cb..14500496ebf3 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -160,10 +160,14 @@ base::win::ScopedHICON ReadICOFromPath(int size, const base::FilePath& path) { LR_LOADFROMFILE))); } -void ReadImageSkiaFromICO(gfx::ImageSkia* image, HICON icon) { +bool ReadImageSkiaFromICO(gfx::ImageSkia* image, HICON icon) { // Convert the icon from the Windows specific HICON to gfx::ImageSkia. std::unique_ptr bitmap(IconUtil::CreateSkBitmapFromHICON(icon)); + if (!bitmap) + return false; + image->AddRepresentation(gfx::ImageSkiaRep(*bitmap, 1.0f)); + return true; } #endif diff --git a/spec/api-native-image-spec.js b/spec/api-native-image-spec.js index 4ada22af9ed1..7e49cbf78e51 100644 --- a/spec/api-native-image-spec.js +++ b/spec/api-native-image-spec.js @@ -9,6 +9,7 @@ describe('nativeImage module', () => { it('returns an empty image for invalid paths', () => { assert(nativeImage.createFromPath('').isEmpty()) assert(nativeImage.createFromPath('does-not-exist.png').isEmpty()) + assert(nativeImage.createFromPath('does-not-exist.ico').isEmpty()) }) it('loads images from paths relative to the current working directory', () => { @@ -47,5 +48,15 @@ describe('nativeImage module', () => { // If all bytes are null, that's Bad assert.equal(nsimage.reduce((acc, x) => acc || (x !== 0), false), true) }) + + it('loads images from .ico files on Windows', () => { + if (process.platform !== 'win32') return + + const imagePath = path.join(__dirname, 'fixtures', 'assets', 'icon.ico') + const image = nativeImage.createFromPath(imagePath) + assert(!image.isEmpty()) + assert.equal(image.getSize().height, 256) + assert.equal(image.getSize().width, 256) + }) }) }) diff --git a/spec/fixtures/assets/icon.ico b/spec/fixtures/assets/icon.ico new file mode 100644 index 000000000000..aa0917755465 Binary files /dev/null and b/spec/fixtures/assets/icon.ico differ