ImageView
A View that displays an image.
进程: 主进程
app 模块出发 ready 事件之后方可使用这个模块。
Useful for showing splash screens that will be swapped for WebContentsViews
when the content finishes loading.
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://electronjs.org')
Class: ImageView extends View
History
| Version(s) | Changes |
|---|---|
None | API ADDED |
A View that displays an image.
进程: 主进程
ImageView inherits from View.
ImageView is an EventEmitter.
警告
Electron 的内置类,不能被继承。 更多信息可以查看 常见问答。
new ImageView() Experimental
History
| Version(s) | Changes |
|---|---|
None | API ADDED |
Creates an ImageView.
实例方法
The following methods are available on instances of the ImageView class, in
addition to those inherited from View:
image.setImage(image) Experimental
History
| Version(s) | Changes |
|---|---|
None | API ADDED |
imageNativeImage
Sets the image for this ImageView. Note that only image formats supported by
NativeImage can be used with an ImageView.