index.d.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import type { DisplayObject } from '@pixi/display';
  2. import type { ExtensionMetadata } from '@pixi/core';
  3. import type { IRendererPlugin } from '@pixi/core';
  4. import { Rectangle } from '@pixi/math';
  5. import type { Renderer } from '@pixi/core';
  6. import { RenderTexture } from '@pixi/core';
  7. /**
  8. * This class provides renderer-specific plugins for exporting content from a renderer.
  9. * For instance, these plugins can be used for saving an Image, Canvas element or for exporting the raw image data (pixels).
  10. *
  11. * Do not instantiate these plugins directly. It is available from the `renderer.plugins` property.
  12. * See {@link PIXI.CanvasRenderer#plugins} or {@link PIXI.Renderer#plugins}.
  13. * @example
  14. * // Create a new app (will auto-add extract plugin to renderer)
  15. * const app = new PIXI.Application();
  16. *
  17. * // Draw a red circle
  18. * const graphics = new PIXI.Graphics()
  19. * .beginFill(0xFF0000)
  20. * .drawCircle(0, 0, 50);
  21. *
  22. * // Render the graphics as an HTMLImageElement
  23. * const image = app.renderer.plugins.extract.image(graphics);
  24. * document.body.appendChild(image);
  25. * @memberof PIXI
  26. */
  27. declare class Extract_2 implements IRendererPlugin {
  28. /** @ignore */
  29. static extension: ExtensionMetadata;
  30. private renderer;
  31. /**
  32. * @param renderer - A reference to the current renderer
  33. */
  34. constructor(renderer: Renderer);
  35. /**
  36. * Will return a HTML Image of the target
  37. * @param target - A displayObject or renderTexture
  38. * to convert. If left empty will use the main renderer
  39. * @param format - Image format, e.g. "image/jpeg" or "image/webp".
  40. * @param quality - JPEG or Webp compression from 0 to 1. Default is 0.92.
  41. * @returns - HTML Image of the target
  42. */
  43. image(target: DisplayObject | RenderTexture, format?: string, quality?: number): HTMLImageElement;
  44. /**
  45. * Will return a base64 encoded string of this target. It works by calling
  46. * `Extract.getCanvas` and then running toDataURL on that.
  47. * @param target - A displayObject or renderTexture
  48. * to convert. If left empty will use the main renderer
  49. * @param format - Image format, e.g. "image/jpeg" or "image/webp".
  50. * @param quality - JPEG or Webp compression from 0 to 1. Default is 0.92.
  51. * @returns - A base64 encoded string of the texture.
  52. */
  53. base64(target: DisplayObject | RenderTexture, format?: string, quality?: number): string;
  54. /**
  55. * Creates a Canvas element, renders this target to it and then returns it.
  56. * @param target - A displayObject or renderTexture
  57. * to convert. If left empty will use the main renderer
  58. * @param frame - The frame the extraction is restricted to.
  59. * @returns - A Canvas element with the texture rendered on.
  60. */
  61. canvas(target?: DisplayObject | RenderTexture, frame?: Rectangle): HTMLCanvasElement;
  62. /**
  63. * Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
  64. * order, with integer values between 0 and 255 (included).
  65. * @param target - A displayObject or renderTexture
  66. * to convert. If left empty will use the main renderer
  67. * @param frame - The frame the extraction is restricted to.
  68. * @returns - One-dimensional array containing the pixel data of the entire texture
  69. */
  70. pixels(target?: DisplayObject | RenderTexture, frame?: Rectangle | PixelExtractOptions): Uint8Array;
  71. private _rawPixels;
  72. /** Destroys the extract. */
  73. destroy(): void;
  74. /**
  75. * Takes premultiplied pixel data and produces regular pixel data
  76. * @private
  77. * @param pixels - array of pixel data
  78. * @param out - output array
  79. */
  80. static arrayPostDivide(pixels: number[] | Uint8Array | Uint8ClampedArray, out: number[] | Uint8Array | Uint8ClampedArray): void;
  81. }
  82. export { Extract_2 as Extract }
  83. /**
  84. * this interface is used to extract only a single pixel of Render Texture or Display Object
  85. * if you use this Interface all fields is required
  86. * @deprecated
  87. * @example
  88. * test: PixelExtractOptions = { x: 15, y: 20, resolution: 4, width: 10, height: 10 }
  89. */
  90. export declare interface PixelExtractOptions {
  91. x: number;
  92. y: number;
  93. height: number;
  94. resolution: number;
  95. width: number;
  96. }
  97. export { }