[英]Adobe Air and Canvas not working
This should be a simple Air App.这应该是一个简单的 Air App。 I am using Dreamweaver CS5.5 and creating an Air App.我正在使用 Dreamweaver CS5.5 并创建一个 Air App。 I cannot get the Canvas to load an image on function. I can get the image to load onLoad.我无法让 Canvas 在 function 上加载图像。我可以让图像加载 onLoad。 The objective is to get an image to draw on canvas then resize and toDataURL to an img tag.目标是获取要在 canvas 上绘制的图像,然后调整大小并将 toDataURL 设置为 img 标签。 What am I doing wrong?我究竟做错了什么? Here is the code:这是代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
function getImage(url){
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var img = new Image();
img.src=url;
img.onload = function(){
context.drawImage(img, 0,0,width,height);
var dataurl = canvas.toDataURL();
document.getElementById('image').src = dataurl;
};
var MAX_WIDTH = 140;
var MAX_HEIGHT = 200;
var width = img.width;
var height = img.height;
if (width > height) {
if (width > MAX_WIDTH) {
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
}
} else {
if (height > MAX_HEIGHT) {
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
}
}
canvas.width = width;
canvas.height = height;
}
</script>
</head>
<body>
<canvas id="canvas"></canvas>
<img id="image" src="" />
<button onClick="javascript:getImage('https://www.google.com/images/srpr/logo3w.png');">Get Image</button>
</body>
</html>
I think the that line is giving you problems:我认为那条线给你带来了问题:
<button onClick="javascript:getImage('https://www.google.com/images/srpr/logo3w.png');">Get Image</button>
The code defined in a link using the javascript: URL scheme is ignored in the application sandbox.使用 javascript:URL 方案的链接中定义的代码在应用程序沙箱中被忽略。 No unsafe JavaScript error is generated.不会产生不安全的 JavaScript 错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.