有没有办法用R转换图像?例如JPEG到GIF

时间:2021-07-11 19:13:09

I wish to display images in a tcltk window (not in a R device) using R but the simpliest method (below) supports only GIF files :

我希望使用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)

and I my files are png/jpeg (file containing histograms generated by my program itself)

我的文件是png / jpeg(包含我的程序本身生成的直方图的文件)

someone has an idea to do that conversion ?

有人有想法进行转换吗?

thank you

1 个解决方案

#1


1  

Despite the warnings this seems to succeed:

尽管有警告这似乎成功了:

 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

#1


1  

Despite the warnings this seems to succeed:

尽管有警告这似乎成功了:

 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