ImageView
显示图片的视图。
¥A View that displays an image.
进程:主进程
¥Process: Main
在 app 模块的 ready 事件发出之前,该模块无法使用。
¥This module cannot be used until the ready event of the app
module is emitted.
用于显示启动画面,内容加载完成后将切换为 WebContentsView。
¥Useful for showing splash screens that will be swapped for WebContentsViews
when the content finishes loading.
请注意,ImageView 处于实验阶段,将来可能会更改或移除。
¥Note that ImageView is experimental and may be changed or removed in the future.
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.nodejs.cn')
类:ImageView 扩展了 View
¥Class: ImageView extends View
显示图片的视图。
¥A View that displays an image.
进程:主进程
¥Process: Main
ImageView 继承自 View。
¥ImageView inherits from View.
ImageView 是 EventEmitter。
¥ImageView is an EventEmitter.
[!警告] Electron 的内置类无法在用户代码中进行子类化。更多信息,请参阅 常见问题解答。
¥[!WARNING] Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.
new ImageView() 实验性的
¥new ImageView() Experimental
创建一个 ImageView。
¥Creates an ImageView.
实例方法
¥Instance Methods
除了从 View 继承的方法外,ImageView 类的实例上还提供了以下方法:
¥The following methods are available on instances of the ImageView class, in
addition to those inherited from View:
image.setImage(image) 实验性的
¥image.setImage(image) Experimental
imageNativeImage
设置此 ImageView 的图片。请注意,只有 NativeImage 支持的图片格式才能与 ImageView 一起使用。
¥Sets the image for this ImageView. Note that only image formats supported by
NativeImage can be used with an ImageView.