UNPKG

fabric-texture

Version:

This JavaScript library enables fast and efficient image distortion transformations using Canvas 2D.

59 lines (58 loc) 2.07 kB
import type { Texture } from '../texture.class'; /** * 创建基于 Canvas 2D 的贴图渲染器 * * 将源图像按照指定的变形网格渲染到目标画布上。 * * @param texture - 贴图对象,包含变形网格和渲染选项 * @param source - 源图像画布 * @param destination - 目标渲染画布 * @param options - 渲染选项 * - x: 渲染位置 X 坐标 * - y: 渲染位置 Y 坐标 * - width: 渲染宽度 * - height: 渲染高度 * - sourceScale: 源图像缩放比例,默认为 1 * - destinationScale: 目标画布缩放比例,默认为 1 * @param utils - 工具函数集合 * * @returns 渲染后的目标画布 */ export declare const createCanvas2DTexture: <Canvas extends HTMLCanvasElement | OffscreenCanvas>(texture: Texture, source: HTMLCanvasElement, destination: Canvas, options: { x: number; y: number; width: number; height: number; sourceScale?: number; destinationScale?: number; }, utils: Record<string, (...args: any) => any>) => Canvas; /** * 创建贴图渲染器的便捷方法 * * 提供一个简化的接口来创建和渲染贴图: * - 自动创建目标画布(如果未提供) * - 自动计算画布尺寸 * - 内置所有必需的工具函数 * * @param texture - 贴图对象,包含变形网格和渲染选项 * @param source - 源图像画布 * @param destination - 目标渲染画布,如果为 null 则自动创建 * @param options - 渲染配置 * - x: 渲染位置 X 坐标 * - y: 渲染位置 Y 坐标 * - width: 渲染宽度 * - height: 渲染高度 * - sourceScale: 源图像缩放比例,默认为 1 * - destinationScale: 目标画布缩放比例,默认为 1 * * @returns 渲染完成的画布对象 */ declare const createTexture: (texture: Texture, source: HTMLCanvasElement, destination: HTMLCanvasElement | null, options: { x: number; y: number; width: number; height: number; sourceScale?: number; destinationScale?: number; }) => HTMLCanvasElement; export default createTexture;