2013-11-28 24 views
1

我在Android的WebView中使用HTML5來繪製圖像:HTML5畫布繪製圖像 「未捕獲的錯誤:INDEX_SIZE_ERR:DOM異常1」,在Android的web視圖

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 

我仍收到錯誤未被捕獲的錯誤:INDEX_SIZE_ERR:DOM異常1戰平,在圖像線。

有沒有人有任何想法? 感謝

回答

0

嗯,我找到了解決辦法,如果

sw = _width; 
sh = _height; 

被替換爲:

sw = _width -40; 
sh = _height -40; 

雖然我找不到原因,爲什麼會這樣?

相關問題