Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ImageLoader

A loader for loading an Image. This is used internally by the CubeTextureLoader, ObjectLoader and TextureLoader.

Examples

WebGL / loader / obj | WebGL / shaders / ocean

Code Example

// instantiate a loader
const loader = new THREE.ImageLoader();
// load a image resource
loader.load(
'textures/skyboxsun25degtest.png', // resource URL
function ( image ) { // onLoad callback
// use the image, e.g. draw part of it on a canvas
const canvas = document.createElement( 'canvas' );
const context = canvas.getContext( '2d' );
context.drawImage( image, 100, 100 );
},
undefined, // onProgress callback currently not supported
function () { // onError callback
console.error( 'An error happened.' );
}
);

Please note three.js r84 dropped support for ImageLoader progress events. For an ImageLoader that supports progress events, see this thread.

Hierarchy

Index

Constructors

constructor

Properties

crossOrigin

crossOrigin: string

The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS. Default is anonymous.

default

'anonymous'

manager

The loadingManager the loader is using. Default is DefaultLoadingManager.

path

path: string

The base path from which the asset will be loaded. Default is the empty string.

default

''

requestHeader

requestHeader: {}

The request header used in HTTP request. See .setRequestHeader. Default is empty object.

default

{}

Type declaration

  • [header: string]: string

resourcePath

resourcePath: string

The base path from which additional resources like textures will be loaded. Default is the empty string.

default

''

withCredentials

withCredentials: boolean

Whether the XMLHttpRequest uses credentials. See .setWithCredentials. Default is false.

default:

false

Methods

load

  • load(url: string, onLoad?: (image: HTMLImageElement) => void, onProgress?: (event: ProgressEvent<EventTarget>) => void, onError?: (event: ErrorEvent) => void): HTMLImageElement
  • Begin loading from url and return the image object that will contain the data.

    Parameters

    • url: string

      The path or URL to the file. This can also be a Data URI.

    • Optional onLoad: (image: HTMLImageElement) => void

      Will be called when load completes. The argument will be the loaded image.

        • (image: HTMLImageElement): void
        • Parameters

          • image: HTMLImageElement

          Returns void

    • Optional onProgress: (event: ProgressEvent<EventTarget>) => void

      This callback function is currently not supported.

        • (event: ProgressEvent<EventTarget>): void
        • Parameters

          • event: ProgressEvent<EventTarget>

          Returns void

    • Optional onError: (event: ErrorEvent) => void

      Will be called when load errors.

        • (event: ErrorEvent): void
        • Parameters

          • event: ErrorEvent

          Returns void

    Returns HTMLImageElement

loadAsync

  • loadAsync(url: string, onProgress?: (event: ProgressEvent<EventTarget>) => void): Promise<HTMLImageElement>
  • Begin loading from url and return the image object that will contain the data.

    Parameters

    • url: string

      The path or URL to the file. This can also be a Data URI.

    • Optional onProgress: (event: ProgressEvent<EventTarget>) => void

      This callback function is currently not supported.

        • (event: ProgressEvent<EventTarget>): void
        • Parameters

          • event: ProgressEvent<EventTarget>

          Returns void

    Returns Promise<HTMLImageElement>

setCrossOrigin

setPath

setRequestHeader

setResourcePath

setWithCredentials

Generated using TypeDoc