我在這段代碼中遇到了麻煩(我正在從本地PC上運行)。Canvas麻煩document.write
請您幫忙。
我的代碼如下:
<html>
<head>
<title>My Test</title>
<script src="../jquery/js/jquery-1.9.0.min.js"></script>
</head>
<body>
<script>
var _canvas = document.createElement('canvas');
_canvas.width="100";
_canvas.height="100";
var _context = _canvas.getContext("2d");
var _img = new Image();
_img.src = "image/myImgTest.png";
var _url;
_img.onload = function() {
DrawScreen(); // just some process: drawing image
_url = _canvas.toDataURL();
alert("test"); **// this alert is printed on FF not on Chrome ???**
// window.location = url; **// With this command on FF, I show my Image**
document.write("<img src='"+url+"' >"); **// on FF, I show my image but when I would like to see the source code on my current page, there is nothing just blank ?? And on Chrome, I never show my image.**
**// In fact, I am expected to generate something like this: <img src="data:image/png;base64,iVBORw0KGgo....."> at this place **
};
function DrawScreen() {
// my process
}
</script>
</body>
</html>
* //其實,我預計將產生這樣的:在這個地方*
即使我會強烈建議不要使用'document.write'時下...你沒有表現出'DrawScreen()',你理應複製'_img'到'_canvas' – devnull69 2013-02-27 11:18:40
我的功能像這樣:function drawScreen(){ \t _context.drawImage(_img,20,20,100,100,0,0,100,100); }; – user2056649 2013-02-27 12:26:03
我的功能是這樣的:function drawScreen(){_context.drawImage(_img,20,20,100,100,0,0,100,100); };一些想法? – user2056649 2013-02-28 05:26:07