这个问题在这里已经有了答案:
How to plot with a png as background? [duplicate]
(2 个回答)
7年前关闭。
... 理想情况下,如果不是 JPEG,则使用 PNG 图像文件。我可以加载一只苍蝇
library(png)
img = readPNG("chart.png")
但我被困在那里。目标是在图像上输入“Hello world”并保存它。
谢谢你。
最佳答案
我认为这应该工作得很好
library(png)
#read file
img<-readPNG("33.png")
#get size
h<-dim(img)[1]
w<-dim(img)[2]
#open new file for output
png("out.png", width=w, height=h)
par(mar=c(0,0,0,0), xpd=NA, mgp=c(0,0,0), oma=c(0,0,0,0), ann=F)
plot.new()
plot.window(0:1, 0:1)
#fill plot with image
usr<-par("usr")
rasterImage(img, usr[1], usr[3], usr[2], usr[4])
#add text
text(.5,.5, "hello", cex=5, col=rgb(.2,.2,.2,.7))
#close image
dev.off()
关于r - 如何在 R : load an image file, 中在图像上打印文本,保存修改后的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23807021/