PIXI.Extract

class Extract implements IRendererPlugin

This class provides renderer-specific plugins for exporting content from a renderer. For instance, these plugins can be used for saving an Image, Canvas element or for exporting the raw image data (pixels).

Do not instantiate these plugins directly. It is available from the renderer.plugins property. See PIXI.CanvasRenderer#plugins or {@link PIXI.Renderer#plugins}.


 // Create a new app (will auto-add extract plugin to renderer)
 const app = new PIXI.Application();

 // Draw a red circle
 const graphics = new PIXI.Graphics()
     .beginFill(0xFF0000)
     .drawCircle(0, 0, 50);

 // Render the graphics as an HTMLImageElement
 const image = app.renderer.plugins.extract.image(graphics);
 document.body.appendChild(image);

Constructor


new PIXI.Extract(renderer: PIXI.Renderer) → {}
Parameters:
Name Type Description
renderer PIXI.Renderer

A reference to the current renderer

Summary


Methods from Extract

string
base64(target: PIXI.DisplayObject | PIXI.RenderTexture, format: string, quality: number)
HTMLCanvasElement
canvas(target: PIXI.DisplayObject | PIXI.RenderTexture, frame: PIXI.Rectangle)
void
destroy()

Destroys the extract.

HTMLImageElement
image(target: PIXI.DisplayObject | PIXI.RenderTexture, format: string, quality: number)
Uint8Array
pixels(target: PIXI.DisplayObject | PIXI.RenderTexture, frame: PIXI.Rectangle | PixelExtractOptions)

Public Methods


base64 Extract.ts:83
base64(target: PIXI.DisplayObject | PIXI.RenderTexture, format: string, quality: number) → {string}

Will return a base64 encoded string of this target. It works by calling Extract.getCanvas and then running toDataURL on that.

Parameters:
Name Type Attributes Description
target PIXI.DisplayObject | PIXI.RenderTexture

A displayObject or renderTexture to convert. If left empty will use the main renderer

format string

<optional>

Image format, e.g. "image/jpeg" or "image/webp".

quality number

<optional>

JPEG or Webp compression from 0 to 1. Default is 0.92.

Returns:
Type Description
string
  • A base64 encoded string of the texture.
canvas Extract.ts:97
canvas(target: PIXI.DisplayObject | PIXI.RenderTexture, frame: PIXI.Rectangle) → {HTMLCanvasElement}

Creates a Canvas element, renders this target to it and then returns it.

Parameters:
Name Type Attributes Description
target PIXI.DisplayObject | PIXI.RenderTexture

A displayObject or renderTexture to convert. If left empty will use the main renderer

frame PIXI.Rectangle

<optional>

The frame the extraction is restricted to.

Returns:
Type Description
HTMLCanvasElement
  • A Canvas element with the texture rendered on.
destroy Extract.ts:273
destroy() → {void}

Destroys the extract.

Returns:
Type Description
void
image Extract.ts:66
image(target: PIXI.DisplayObject | PIXI.RenderTexture, format: string, quality: number) → {HTMLImageElement}

Will return a HTML Image of the target

Parameters:
Name Type Attributes Description
target PIXI.DisplayObject | PIXI.RenderTexture

A displayObject or renderTexture to convert. If left empty will use the main renderer

format string

<optional>

Image format, e.g. "image/jpeg" or "image/webp".

quality number

<optional>

JPEG or Webp compression from 0 to 1. Default is 0.92.

Returns:
Type Description
HTMLImageElement
  • HTML Image of the target
pixels Extract.ts:197
pixels(target: PIXI.DisplayObject | PIXI.RenderTexture, frame: PIXI.Rectangle | PixelExtractOptions) → {Uint8Array}

Will return a one-dimensional array containing the pixel data of the entire texture in RGBA order, with integer values between 0 and 255 (included).

Parameters:
Name Type Attributes Description
target PIXI.DisplayObject | PIXI.RenderTexture

<optional>

A displayObject or renderTexture to convert. If left empty will use the main renderer

frame PIXI.Rectangle | PixelExtractOptions

<optional>

The frame the extraction is restricted to.

Returns:
Type Description
Uint8Array
  • One-dimensional array containing the pixel data of the entire texture

Powered by webdoc!