有人知道如何在不保存图片的情况下将简单的图转换为png_format吗?换句话说,我正在寻找一种将简单图解转换为像素的最直接,最快的方法(如果尚未实现的话)(请参见下面的代码)...
编辑:由@hrbrmstr给出的建议已实现...
## SolutionOne
library(png)
testONE <- system.time({
## Save plot as .png
tmp <- tempfile()
png(tmp, width = 800, height = 600, res = 72)
plot(1:10, pch = 19, col = "yellowgreen", cex = 20)
dev.off()
## Read .png
asPixels <- readPNG(tmp)
## Information needed (e.g. RGB)
dim(asPixels)
pixONE <- asPixels[300, 400, 1:3]
})
## SolutionTwo
library(magick)
testTWO <- system.time({
## Produce image using graphics device
fig <- image_graph()
plot(1:10, pch = 19, col = "yellowgreen", cex = 20)
## Information needed
pixTWO <- image_data(fig)[1:3, 400, 300]
dev.off()
})
testONE # elapsed time: 0.064
testTWO # elapsed time: 0.164
感谢您的提示...