我希望使用R在tcltk窗口(不在R设备中)显示图像,但最简单的方法(下面)仅支持GIF文件:
require(tcltk)
tcl("image","create","photo", "imageID", file="a.gif")
w <- tktoplevel()
l <- ttklabel(w, image="imageID", compound="image")
tkpack(l)
我的文件是png / jpeg(包含我程序自己生成的直方图的文件)
有人有想法进行转换吗?
谢谢
答案 0 :(得分:1)
尽管有警告,这似乎还是成功了:
png("test.png")
plot(1,1)
dev.off()
#quartz
# 2
library(png)
help(package="png")
img <- readPNG("test.png")
str(img)
# num [1:480, 1:480, 1:4] 1 1 1 1 1 1 1 1 1 1 ...
require(caTools)
#Loading required package: caTools
write.gif(img, "test.gif", scale="always")
#-----------------
Warning message:
In if (col == "jet") col = colorRampPalette(c("#00007F", "blue", :
the condition has length > 1 and only the first element will be used