跳转至

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。

实例方法

除了从 View 继承的方法之外,以下方法可用于 ImageView 类的实例:

image.setImage(image) 实验性

  • image NativeImage

为这个 ImageView 设置图像。请注意,只有 NativeImage 支持的图像格式才能与 ImageView 一起使用。

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