在 R 中:通过链接引用将位图嵌入到 SVG 图像中

发布于 2025-01-08 06:30:50 字数 996 浏览 3 评论 0原文

我想在 R 中通过链接引用将位图图像嵌入到 SVG 绘图图像中。

图像可以通过 链接引用 甚至 data,例如:

<image x="50" y="50"  width="100" height="100" xlink:href="myimage.png">
<image x="50" y="50"  width="100" height="100" xlink:href="data:image/png;base64,[data]">

我的目标是减少我生成的 SVG 图像文件的大小和复杂性(我的地块大约有10⁶ 分:这是一个 250Mb SVG 文件,需要 8Gb RAM 才能使用 inkscape 进行编辑。我正在考虑将大部分绘图生成为位图图像(例如 PNG),并将绘图的一些关键元素(稍后必须手动编辑的元素)生成为 SVG 图像,然后使用技巧组合这两个图像我刚刚在上面描述过。

我尝试过使用 pixmap 库,但位图是作为矢量图像逐点添加的,这不会减少总体文件大小:

library(pixmap)
svg("image.svg")
x <- -5:5 ; y <- x^2 ;  plot(x,y)
bitmap <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1])
addlogo(bitmap, px=c(-3, 3), py=c(0, 6), asp=1)
dev.off()

任何有关执行此操作的方法的想法都非常受欢迎。

非常感谢。

I would like, in R, to embed a bitmap image by link reference into a SVG plot image.

Images may be included in an SVG by link reference, or even data, for example:

<image x="50" y="50"  width="100" height="100" xlink:href="myimage.png">
<image x="50" y="50"  width="100" height="100" xlink:href="data:image/png;base64,[data]">

My objective is to reduce the size and complexity of the SVG image files I am generating (My plots have about 10⁶ points: that's a 250Mb SVG file requiring 8Gb RAM for editing with inkscape ). I was thinking generating most of the plot as a bitmap image (say PNG), and some key elements of the plot (the ones that will later have to be edited by hand) as an SVG image, and then combine both images using the trick I've just described above.

I have tried using the pixmap library, but the bitmap is added as a vectorial image, dot by dot, which would not reduce the overall file size:

library(pixmap)
svg("image.svg")
x <- -5:5 ; y <- x^2 ;  plot(x,y)
bitmap <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1])
addlogo(bitmap, px=c(-3, 3), py=c(0, 6), asp=1)
dev.off()

Any thoughts on the way to do this would be more than welcome.

Many thanks.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文