Is there a way to convert image with R ? JPEG to GIF for example

戏子无情 提交于 2019-12-24 04:12:00

问题


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 :

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)

someone has an idea to do that conversion ?

thank you


回答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


来源:https://stackoverflow.com/questions/17581954/is-there-a-way-to-convert-image-with-r-jpeg-to-gif-for-example

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!