English 中文(简体)
图卢布装载基地64
原标题:Trouble loading Base64 string to canvas

我试图将基地64从我的数据库装上水面。

我从采取反向方法中获得了这一指示: 我在利用信道后将其节省到我的数据库。 因此,我现在要把它重新装上另一个信道。 我已经尝试了这一守则,我在网上和在StackOverflow的其他地方也这样做了,但似乎并没有奏效。

<script type="text/javascript">
  $(document).ready(function(){
    var canvas = document.getElementById("loading_canvas");
    var ctx = canvas.getContext("2d");

    var image = new Image();

    $.post( doodles/load , function(data) {
      image.src = data;
    });
    ctx.drawImage(image, 0, 0);
  });
</script>

我在我数据库的数据中填满了一条警示。

如果Ialert(>>data var,则显示编码的S64号指示。 因此,这确实没有错。 最后,我充满空洞的vas。

任何人都知道我在这里做错了什么? 感谢很多!

最佳回答

在图像负荷活动之后绘制图像:

var image = new Image();
image.onload = function () {
    ctx.drawImage(image, 0, 0);
}

$.post( doodles/load , function(data) {
    image.src = data;
});

The src needs to have a full data URL and not just a bunch of base64 data, so double-check that too. Example (from Wikipedia):

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />

问题回答

如果您的数据为<>base64, data-uri,你就只能移动一条线,一切都运转良好。

<script type="text/javascript">
  $(document).ready(function(){
      var canvas = document.getElementById("loading_canvas");
      var ctx = canvas.getContext("2d");

      var image = new Image();

      $.post( doodles/load , function(data) {
      image.src = data;
      ctx.drawImage(image, 0, 0);
    });
  });
</script>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签