我在检索画布上显示的图像的base64版本时遇到问题。我已经看了其他问题,但没有任何解决方案,包括canvas2image似乎工作。HTML画布图像到Base64问题
这里是我的代码:
<!DOCTYPE>
<html>
<head>
<style>#canvas {cursor: pointer;}</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script type="text/javascript">
var can = document.getElementById('canvas');
var ctx = can.getContext('2d');
var img = new Image();
img.onload = function(){
can.width = img.width;
can.height = img.height;
ctx.drawImage(img, 0, 0, img.width, img.height);
}
img.src = 'http://sstatic.net/stackoverflow/img/newsletter-ad.png';
can.onclick = function() {
ctx.translate(img.width-1, img.height-1);
ctx.rotate(Math.PI);
ctx.drawImage(img, 0, 0, img.width, img.height);
};
document.write(can.toDataURL()); //isn't writing the correct base64 image
</script>
</body>
</html>
这里的测试环节:http://jsfiddle.net/mrchief/hgTdM/1/感谢,Mrchief
我需要的是在画布上的图像的base64输出正确的。
问题是,它不会输出正确的base64版本的图像..但正如你所看到的,画布内的图像显示没有任何问题。
我已经测试了镀铬&火狐
非常感谢..
那么,输出什么* *然后呢? –
在Chrome&FF5中适合我:http://jsfiddle.net/mrchief/hgTdM/1/ – Mrchief
在IE9和Firefox 6中可以正常工作。 – Caimen