【问题标题】:How do I turn a canvas element that uses an image served by ImageService as background to a downloadable image?如何将使用 ImageService 提供的图像作为背景的画布元素转换为可下载图像?
【发布时间】:2013-01-25 05:48:27
【问题描述】:

我正在编写一个应用程序,用户可以在其中上传图像、绘制图像并保存结果。我试图通过使用画布元素并使用上传的图像作为其背景来实现这一点。我正在通过 ImageService 检索图像。下面是初始化画布的客户端代码:

var image = new Image();
image.src = "http://some.google.domain.com/foobar123";
var ctx = canvas.getContext('2d')
image.onload = function() {
    ctx.drawImage(image, 0, 0);
};

现在用户可以在图像上绘制东西了。

然后当用户想要保存图片时,我调用:

canvas.toDataURL("image/png")

这会在 Chrome 中出现此错误:

Error: SecurityError: DOM Exception 18.
"Error: An attempt was made to break through the security policy of the user agent."

我假设 Chrome 不喜欢它,因为图像是从某个谷歌域提供的,这与我的应用引擎应用的域不同。

有解决办法吗?

提前致谢。

【问题讨论】:

  • 通过您的服务器传递请求。

标签: javascript html google-app-engine google-chrome


【解决方案1】:

作为一种解决方法,我现在使用 BlobstoreService 来提供图像数据,而不是 ImageService。这种方法提供与我的应用相同域的图像,但您失去了使用 Google 的静态图像服务基础架构的所有好处。

【讨论】:

  • 您能否详细说明您的解决方案?所以你根本不做这个客户端?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-05
  • 2021-08-04
相关资源
最近更新 更多