问题
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