ImageView
一个用于显示图像的视图。
进程: 主进程
在发出 app 模块的 ready 事件之前,此模块将无法使用。
适用于显示启动画面,当内容加载完成后,这些启动画面将被 WebContentsView 替换。
请注意,ImageView 仍处于实验阶段,未来可能会更改或删除。
const { BaseWindow, ImageView, nativeImage, WebContentsView } = require('electron')
const path = require('node:path')
const win = new BaseWindow({ width: 800, height: 600 })
// Create a "splash screen" image to display while the WebContentsView loads
const splashView = new ImageView()
const splashImage = nativeImage.createFromPath(path.join(__dirname, 'loading.png'))
splashView.setImage(splashImage)
win.setContentView(splashView)
const webContentsView = new WebContentsView()
webContentsView.webContents.once('did-finish-load', () => {
// Now that the WebContentsView has loaded, swap out the "splash screen" ImageView
win.setContentView(webContentsView)
})
webContentsView.webContents.loadURL('https://electron.js.cn')
类: ImageView 继承自 View
一个用于显示图像的视图。
进程: 主进程
ImageView 继承自 View。
ImageView 是一个 EventEmitter。
警告
Electron 的内置类不能在用户代码中被继承。有关更多信息,请参阅 FAQ。
new ImageView() 实验性
创建一个 ImageView。
实例方法
除了从 View 继承的方法之外,ImageView 类的实例还具有以下方法:
image.setImage(image) 实验性
imageNativeImage
为这个 ImageView 设置图像。请注意,只有 NativeImage 支持的图像格式才能与 ImageView 一起使用。