Html5 canvas HTML5画布绘制图像“;未捕获错误:索引“大小”错误:DOM异常1;在Android Webview中

Html5 canvas HTML5画布绘制图像“;未捕获错误:索引“大小”错误:DOM异常1;在Android Webview中,html5-canvas,android-webview,drawimage,Html5 Canvas,Android Webview,Drawimage,我正在android webview中使用Html5绘制图像: var img = new Image(); img.src = arrayImg[count]; img.onload = function() { console.log('Onload called::'+count); canvasAppend(img,count); initialiseImages(count + 1 ); }; 在这里: func

我正在android webview中使用Html5绘制图像:

var img = new Image();
    img.src = arrayImg[count];
    img.onload = function() {
        console.log('Onload called::'+count);
        canvasAppend(img,count);
        initialiseImages(count + 1 );
    };
在这里:

function canvasAppend(img,index){
    var canvas = createCanvasElement(img);
...
}

function createCanvasElement(img) {
    var radius = 20;
    var canvas = document.createElement('canvas');
    canvas.setAttribute('width',  imgWidth);
    canvas.setAttribute('height', imgHeight);
    var _height = img.naturalHeight;
    var _width  = img.naturalWidth;
    var w = false; // width is shorter?
    if (_height > _width) w = true;
    var sx, sy, sw, sh;

    //console.log('_width::'+ _width+'  _height::'+_height);


    if (w) {
        sx = 0;
        sy = _height / 2 - _side / 2;
    } else {
        var _side = _height;
        sx = _width / 2 - _side / 2;
        sy = 0;
    }
    sw = _width;
    sh = _height;

    var cx = canvas.getContext('2d');
    cx.beginPath();
    cx.moveTo(radius, 0);
    cx.lineTo(canvas.width - radius, 0);
    cx.quadraticCurveTo(canvas.width, 0, canvas.width, radius);
    cx.lineTo(canvas.width, canvas.height - radius);
    cx.quadraticCurveTo(canvas.width, canvas.height, canvas.width - radius, canvas.height);
    cx.lineTo(radius, canvas.height);
    cx.quadraticCurveTo(0, canvas.height, 0, canvas.height - radius);
    cx.lineTo(0, radius);
    cx.quadraticCurveTo(0, 0, radius, 0);
    cx.clip();
    console.log('sx::'+ sx+'  sy::'+sy);
    console.log('sw::'+ sw+'  sh::'+sh);
    console.log('img::'+img);
    console.log('imgWidth:::'+imgWidth);
    console.log('imgHeight:::'+imgHeight);
    cx.drawImage(img, sx, sy, sw, sh, 0, 0, imgWidth, imgHeight);
    //  $(canvas).click(coverflow.popup(img));
    return canvas;
}
控制台日志返回的值:

sx::1  sy::0 
sw::250  sh::248
img::[object HTMLImageElement] 
imgWidth:::224.8 
imgHeight:::225.83333333333334 
我仍然得到错误未捕获错误:索引大小错误:DOM异常1在绘制图像线

有人知道吗?
谢谢

我找到了解决办法,如果

sw = _width;
sh = _height;
替换为:

 sw = _width -40;
 sh = _height -40;
虽然我找不到它为什么如此