跳转至

ImageView

一个用于显示图像的 View。

进程:主进程

在 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://electronjs.org')

类:ImageView 继承自 View

创建一个 ImageView。

实例方法

以下方法可用于 ImageView 类的实例,此外还包括从 View 继承的方法:

image.setImage(image) 实验性

  • image NativeImage

为此 ImageView 设置图像。请注意,只能使用 NativeImage 支持的图像格式。

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 el/electron