• Create an HTMLCanvasElement from ImageData.

    Creates a new canvas with the same dimensions as the ImageData and draws the pixel data onto it.

    Parameters

    • imageData: ImageData

      The ImageData to convert

    Returns HTMLCanvasElement

    A new HTMLCanvasElement containing the image data

    Throws

    When canvas context creation fails

    Example

    // Create ImageData programmatically
    const imageData = new ImageData(100, 100);
    const data = imageData.data;
    for (let i = 0; i < data.length; i += 4) {
    data[i] = 255; // R
    data[i + 1] = 0; // G
    data[i + 2] = 0; // B
    data[i + 3] = 255; // A
    }

    const canvas = imageDataToCanvas(imageData);