我们可以在 HTML5 中通过 g.shadowBlur 方法绘制阴影,在大多数浏览器中都可以,除了 Chrome,当我绘制透明图像阴影时,如下所示,我该如何解决这个问题
我的 chrome 版本是“Chrome for Mac OS X,版本 27.0.1453.116”
<!DOCTYPE html>
<html>
<head>
<title>Chrome HTML5 Canvas DrawImage Shadow Bug</title>
<script type="text/javascript">
function drawImage(evt){
var image = evt.target;
var w = image.width;
var h = image.height;
var canvas = document.getElementById('canvas');
var g = canvas.getContext('2d');
g.shadowColor = "#000000";
g.shadowBlur = 10;
g.shadowOffsetX = 0;
g.shadowOffsetY = 0;
g.drawImage(image, 20, 20);
g.fillText("Text shadow in canvas", 10, 20)
}
</script>
</head>
<body>
<img src="http://www.google.com/images/icons/product/chrome-48.png" onload="drawImage(event)" style="-webkit-filter: drop-shadow(0px 0px 10px #222);" />
<div>
<canvas id='canvas' style="background-color: #DDDDDD" />
</div>
</body>
</html>