Chrome在< img>中加载SVG时会出现警告。 [英] Chrome gives a warning when loading an SVG in an <img>

查看:541
本文介绍了Chrome在< img>中加载SVG时会出现警告。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在画布上显示SVG图像文件,我在HTML上有以下行:

In order to display an SVG image file onto a canvas I have the following line on the HTML:

<img id="soundOnImg" src="img/speaker_on.svg" style="display:none"></img>

,然后在画布上绘制:

ctx2d.drawImage($("#soundOnImg")[0], 10, 10, 200, 200);

(使用jQuery $()

(using jQuery $() there)

除了一个烦人之外,Chrome完全正常工作 - Chrome会向我发出以下警告:

This works perfectly except for one annoyance - Chrome gives me the following warning:

Resource interpreted as image but transferred with MIME type image/svg+xml.

此警告是什么意思?

我尝试使用< object> ,而不是< img> 但由于对象元素由于某种原因似乎没有 [0] ,因此失败。

I tried using <object> instead of <img> but this fails since the object element doesn't seem to have a [0] for some reason.

如何解决此问题?

推荐答案

这是Chrome附带的WebKit代码中的错误。 WebInspector.Resource._checkWarning()调用 WebInspector.Resource._mimeTypeIsConsistentWithType()以检查资源的MIME类型。此函数会根据 WebInspector.MIMETypes 对象,其中不包含SVG图像的条目。

This is a bug in the WebKit code bundled with Chrome. WebInspector.Resource._checkWarning() calls WebInspector.Resource._mimeTypeIsConsistentWithType() to check the mime-type of the resource. This function checks the value against the WebInspector.MIMETypes object, which does not contain an entry for SVG images.

这看起来不是固定的在 WebKit中继中,因此您应该可以将其报告为错误

This does not appear to be fixed in WebKit trunk, so you should probably report it as a bug.

这篇关于Chrome在&lt; img&gt;中加载SVG时会出现警告。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆