nativeImage
Создает иконки приложения, в том числе для системного лотка (Windows), дока (macOS), используя файлы PNG и JPG.
Процессы: Основной, Графический
The nativeImage
module provides a unified interface for manipulating system images. These can be handy if you want to provide multiple scaled versions of the same icon or take advantage of macOS template images.
Electron APIs that take image files accept either file paths or NativeImage
instances. An empty and transparent image will be used when null
is passed.
For example, when creating a Tray or setting a BrowserWindow's icon, you can either pass an image file path as a string:
const { BrowserWindow, Tray } = require('electron')
const tray = new Tray('/Users/somebody/images/icon.png')
const win = new BrowserWindow({ icon: '/Users/somebody/images/window.png' })
or generate a NativeImage
instance from the same file:
const { BrowserWindow, nativeImage, Tray } = require('electron')
const trayIcon = nativeImage.createFromPath('/Users/somebody/images/icon.png')
const appIcon = nativeImage.createFromPath('/Users/somebody/images/window.png')
const tray = new Tray(trayIcon)
const win = new BrowserWindow({ icon: appIcon })
Поддерживаемые форматы
Currently, PNG
and JPEG
image formats are supported across all platforms. PNG
is recommended because of its support for transparency and lossless compression.
On Windows, you can also load ICO
icons from file paths. For best visual quality, we recommend including at least the following sizes: