r - 如何在 R : load an image file, 中在图像上打印文本,保存修改后的图像

标签 r image png

这个问题在这里已经有了答案:





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/

相关文章:

r - 使用两个变量进行预测时停止外推

r - 如何在ggplot 2中的填充中按变量排序条形图

jQuery:用 A anchor 标记包装图像标记的最简单方法

javascript - 带变量的 Img src url

android - 如何将可绘制的矢量转换为PNG文件?

python - Python 中网格数据的 PolarColor map 绘图

r - 打乱数据帧,同时保持与另一个数据帧的顺序

jquery - 在图像上显示图像标题

node.js - 图像未保存在 Palm 设备上

javascript - 在javascript中提取png图像像素的值