ImageView
A View that displays an image.
Process: Main
This module cannot be used until the ready event of the app
module is emitted.
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.
Process: Main
ImageView inherits from View.
ImageView is an EventEmitter.
Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.
new ImageView() Experimental
History
| Version(s) | Changes |
|---|---|
None | API ADDED |
Creates an ImageView.
Instance Events
Event: 'bounds-changed'
Inherited from View
Emitted when the view's bounds have changed in response to being laid out. The
new bounds can be retrieved with view.getBounds().
Instance Properties
image.children Readonly
Inherited from View
A View[] property representing the child views of this view.
Instance Methods
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.
image.addChildView(view[, index])
Inherited from View
viewView - Child view to add.indexInteger (optional) - Index at which to insert the child view. Defaults to adding the child at the end of the child list.
If the same View is added to a parent which already contains it, it will be reordered such that it becomes the topmost view.
image.removeChildView(view)
Inherited from View
viewView - Child view to remove.
If the view passed as a parameter is not a child of this view, this method is a no-op.
image.setBounds(bounds[, options])
Inherited from View
boundsRectangle - New bounds of the View.
image.getBounds()
Inherited from View
Returns Rectangle - The bounds of this View, relative to its parent.
image.setBackgroundColor(color)
Inherited from View
colorstring - Color in Hex, RGB, ARGB, HSL, HSLA or named CSS color format. The alpha channel is optional for the hex type.
Examples of valid color values:
- Hex
#fff(RGB)#ffff(ARGB)#ffffff(RRGGBB)#ffffffff(AARRGGBB)
- RGB
rgb\(([\d]+),\s*([\d]+),\s*([\d]+)\)- e.g.
rgb(255, 255, 255)
- e.g.
- RGBA
rgba\(([\d]+),\s*([\d]+),\s*([\d]+),\s*([\d.]+)\)- e.g.
rgba(255, 255, 255, 1.0)
- e.g.
- HSL
hsl\((-?[\d.]+),\s*([\d.]+)%,\s*([\d.]+)%\)- e.g.
hsl(200, 20%, 50%)
- e.g.
- HSLA
hsla\((-?[\d.]+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)- e.g.
hsla(200, 20%, 50%, 0.5)
- e.g.
- Color name
- Options are listed in SkParseColor.cpp
- Similar to CSS Color Module Level 3 keywords, but case-sensitive.
- e.g.
bluevioletorred
- e.g.
Hex format with alpha takes AARRGGBB or ARGB, not RRGGBBAA or RGB.
image.setBorderRadius(radius)
Inherited from View
radiusInteger - Border radius size in pixels.
The area cutout of the view's border still captures clicks.
image.setBackgroundBlur(blurRadius)
Inherited from View
blurRadiusInteger - The radius of the background blur effect (in pixels).
You must set a background color with an alpha channel (e.g. #80ffffff) in order for the blur effect to be visible.
image.setVisible(visible)
Inherited from View
visibleboolean - If false, the view will be hidden from display.
image.getVisible()
Inherited from View
Returns boolean - Whether the view should be drawn. Note that this is
different from whether the view is visible on screen—it may still be obscured
or out of view.