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
here
.
这个错误似乎不存在于任何其他浏览器,包括桌面Safari。如果你在iPad上刷新页面,它似乎也会消失。
drawImage()
?
有人知道为什么会发生这种情况吗?如果有一些特定的值我可以简单地避免,这样就不会发生了。。。或者其他的解决方法?