Maximum size of a element

后端 未结 14 1767
粉色の甜心
粉色の甜心 2020-11-22 07:34

I\'m working with a canvas element with a height of 600 to 1000 pixels and a width of several tens or hundreds of thousands of pixels. However, aft

14条回答
  •  既然无缘
    2020-11-22 08:16

    I don't know how to detect the max possible size without itteration, but you can detect if a given canvas size works by filling a pixel and then reading the colour back out. If the canvas has not rendered then the color you get back will not match. W

    partial code:

    function rgbToHex(r, g, b) {
        if (r > 255 || g > 255 || b > 255)
            throw "Invalid color component";
        return ((r << 16) | (g << 8) | b).toString(16);
    }
    var test_colour = '8ed6ff';
    working_context.fillStyle = '#' + test_colour;
    working_context.fillRect(0,0,1,1);
    var colour_data = working_context.getImageData(0, 0, 1, 1).data;
    var colour_hex = ("000000" + rgbToHex(colour_data[0], colour_data[1], colour_data[2])).slice(-6);
    

提交回复
热议问题