2010-05-20 110 views
0

經過一番艱苦的調試之後,我想我在iPad Safari的canvas.drawImage()實現中發現了一個錯誤。具體地,本超載:iPad的html5 canvas drawimage()實現中的錯誤?

void drawImage(in HTMLImageElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh); 

當切片的圖像和縮放下來,似乎Safari瀏覽器有時忘記切片圖像並簡單地縮放整個圖像下移。這發生在一個隨機的基礎上,但我已經能夠在清除safari緩存後一直在iPad上重現它。下面是代碼:

<script> 
draw = function() { 
    var ctx = document.getElementById('cc').getContext('2d'); 
    var timg = new Image() 
    timg.onload = function() { 
    ctx.fillStyle = 'rgb(100,100,100)'; 
    ctx.fillRect(0,0,256,256); 
    ctx.drawImage(timg, 0,0, 128, 128, 0, 0, 63,63);     
    ctx.drawImage(timg, 0,0, 128, 128, 128, 0, 65,65);    
    }; 
    timg.src = "http://amirshimoni.com/ipadbug1/1234.jpg"; 
}; 
</script> 
<body onload="draw();"> 
<canvas id="cc" width="256" height="128"></canvas> 
</body> 

你可以運行它here或看到從iPad here輸出。

此錯誤似乎並不存在於任何其他瀏覽器上,包括桌面Safari。如果您刷新iPad上的頁面,它似乎也會消失。

我做錯了drawImage()

任何人都可以找出爲什麼會發生這種情況,如果有特定的值,我可以避免,所以它不會發生......或其他解決方法?

+1

如果您認爲您在任何軟件中發現錯誤,請將其報告給開發人員(Apple,在這種情況下爲:http://developer.apple.com/bugreporter/)。獲得報告的錯誤是修復的錯誤。 – 2010-05-20 23:45:15

+0

謝謝,我提交了。 – Amir 2010-05-21 00:14:16

回答

1

此錯誤似乎已在iOS 4.2中修復。至少,我沒有看到它再發生。