2

我希望使用 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(包含由我的程序本身生成的直方图的文件)

有人有想法进行这种转换吗?

谢谢你

4

1 回答 1

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
于 2013-07-11T02:24:21.403 回答