メインコンテンツへ飛ぶ

ImageView

A View that displays an image.

Process: Main

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

A View that displays an image.

Process: Main

ImageView inherits from View.

ImageView is an EventEmitter.

new ImageView() Experimental

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

  • image NativeImage

Sets the image for this ImageView. Note that only image formats supported by NativeImage can be used with an ImageView.