2013-07-10 24 views
2

我希望顯示在tcltk窗口(未在A R裝置)使用R圖像但simpliest方法(下文)僅支持GIF文件:有沒有辦法將圖像轉換爲R? JPEG至GIF例如

require(tcltk) 
tcl("image","create","photo", "imageID", file="a.gif") 
w <- tktoplevel() 
l <- ttklabel(w, image="imageID", compound="image") 
tkpack(l) 

和我在我的文件爲png/jpeg(包含我的程序本身生成的直方圖的文件)

某人有想做這種轉換的想法嗎?

謝謝

+1

或者,你可以使用的ImageMagick的文件格式非常輕鬆轉換。 –

+0

是的,但我希望它是自動的。 – user2551551

+1

@ user2551551 - 你可以使用'system()'調用從R中調用imagemagick,然後繼續快樂的方式。 – thelatemail

回答

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 
+0

行..行得通。但GIF動畫,並沒有顏色。但它的工作原理。 – user2551551

相關問題