如何缩放 SVG同时保持整个像素?

发布于 2024-10-10 10:17:02 字数 227 浏览 0 评论 0原文

我有一个像素艺术风格的图像,打算使用 SVG 缩放到 4 倍大小。但是,以下代码模糊了图像的像素:

<image x="0" y="0" width="1024" height="1024"
    image-rendering="optimizeSpeed"
    xlink:href="pixelart.bmp" />

是否有某些属性可以解决此问题?

I have a pixelart-style image which intend to scale to 4x size with SVG. However, the following code blurs the pixels of the image:

<image x="0" y="0" width="1024" height="1024"
    image-rendering="optimizeSpeed"
    xlink:href="pixelart.bmp" />

Is there some attribute which will resolve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹉夏雨初晴づ 2024-10-17 10:17:02

我认为 image-rendering="optimizeSpeed" 是您可以获得的最接近的结果。正如该属性的规范所述,它“应该使用一种实现快速渲染目标的重采样算法,要求重采样算法至少与最近邻重采样一样好。”因为这是规范中唯一提到“最近邻”的部分,我认为你没有其他选择。

我能找到的唯一相关的东西是 IE9 属性 <代码>-ms-interpolation-mode:最近邻。这是(当然)IE 特定的,并被列为 CSS 属性(因此可能仅适用于 HTML)。

哪个操作系统/浏览器/版本为您提供了插值像素,作为使用该属性进行放大的结果?


另请注意,您可以结合使用 HTML5 Canvas 和 SVG,通过每个像素一个 SVG 完美地重新创建图像:
http://phrogz.net/tmp/canvas_image_zoom_svg.xhtml

I think that image-rendering="optimizeSpeed" is the closest you can get. As the specs for that property state, it "should use a resampling algorithm which achieves the goal of fast rendering, with the requirement that the resampling algorithm shall be at least as good as nearest neighbor resampling." As this is the only section of the spec that mentions "nearest neighbor", I don't think you have any other option.

The only other related thing I can find is the IE9 property -ms-interpolation-mode:nearest-neighbor. This is (of course) IE specific, and is listed as a CSS property (so possibly only applicable to HTML).

Which OS/browser/version is giving you interpolated pixels as a result of upsizing with that attribute?


Also, note that you can use a combination of HTML5 Canvas and SVG to perfectly recreate your image with one SVG <rect> per pixel:
http://phrogz.net/tmp/canvas_image_zoom_svg.xhtml

溺渁∝ 2024-10-17 10:17:02

CSS 值图像渲染:像素化;所以:

<image x="0" y="0" width="1024" height="1024"
    style="image-rendering:pixelated"
    xlink:href="pixelart.bmp" />

这是通过阅读上面“已接受”答案中的答案链接得出的。截至撰写本文时,它还不是官方的,仍然是 CSS4 的“建议”,但 Chrome 似乎已经支持了。

CSS value image-rendering:pixelated; so:

<image x="0" y="0" width="1024" height="1024"
    style="image-rendering:pixelated"
    xlink:href="pixelart.bmp" />

This is from reading through the answer link above, in the "accepted" answer. It is not official as of time of writing, still "Proposed" for CSS4, but appears to be supported by Chrome already.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文