如何使用ios中的Phonegap将图像加载到html5上

时间:2012-06-20 12:02:33

标签: ios html5 cordova

我是phonegap的新手。我们如何在ios中使用phonegap在html5上加载图像?谁能帮我?但它不起作用

DOCTYPE HTML>
<HTML>

<body>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">
Your browser
</canvas>

<script type="text/javascript" charset="utf-8" src="cordova-1.8.1.js"></script>
<script type="text/javascript" src="xui<2.3.2>.js"></script>
<script type="text/javascript" charset="utf-8">

window.onload=function(){
var c=document.getElementById("myCanvas");
var cs=c.getContext("2d")
var img=new Image()
img.src="picture.jpg";
cs.drawingImage(img,0,0);
};

</script>
<img src="picture.jpg"/>
</body>
</HTML>

1 个答案:

答案 0 :(得分:1)

嗨,我无法弄清楚问题,但下面的例子对我有用。

<!DOCTYPE HTML>
<html>
  <head>
    <style>
      body {
        margin: 0px;
        padding: 0px;
      }
      #myCanvas {
        border: 1px solid #9C9898;
      }
    </style>
    <script>
      window.onload = function() {
        var canvas = document.getElementById("myCanvas");
        var context = canvas.getContext("2d");
        var imageObj = new Image();

        imageObj.onload = function() {
          context.drawImage(imageObj, 69, 50);
        };
        imageObj.src = "http://www.html5canvastutorials.com/demos/assets/darth-vader.jpg";
      };

    </script>
  </head>
  <body>
    <canvas id="myCanvas" width="578" height="400"></canvas>
  </body>
</html>

更改指向图像的链接。希望它有效。