有没有办法用R转换图像?以JPEG到GIF为例 [英] Is there a way to convert image with R ? JPEG to GIF for example

查看:85
本文介绍了有没有办法用R转换图像?以JPEG到GIF为例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用R在tcltk窗口中显示图像(不在R设备中),但是最简单的方法(如下所示)仅支持GIF文件:

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)

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

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

有人有想法进行转换吗?

someone has an idea to do that conversion ?

谢谢

推荐答案

尽管警告似乎成功了:

 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

这篇关于有没有办法用R转换图像?以JPEG到GIF为例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆