我试图将360个PNG文件作为gif保存在r(我正在与macOS合作)

问题描述 投票:0回答:1

请让我知道我需要包括的任何其他系统/代码,因为我不熟悉将图像写入计算机。我正在创建360个PNG文件,如下所示:

for(theta in 1:360){
    ic=as.character(theta)
    if(theta<10) ic=paste("00",ic,sep="")
    if(theta>=10 & theta<100) ic=paste("0",ic,sep="") # make filenames the same length
    fn=paste("c:iris360\\HW4_",ic,".png",sep="") #filename
    png(fn,width=1000,height=1000) # save as *.png
    p3(X1,X2, r=100,theta=theta,mainL=paste("theta =",theta))
    # legend("topleft",pch=16,cex=1.5,col=allcl)
    dev.off()
}
system("magick c:iris360\\HW4*.png c:iris.gif") 

p3只是一个函数,它可以将我的矩阵x1和x2带走,并绘制点及其段(让我知道我是否还需要包含它)。但是,我得到了这个错误:

magick: must specify image size iris360HW4*.png' @ error/raw.c/ReadRAWImage/140.

我无法打开GIF文件,因为我的Mac说它已损坏或使用预览未识别的文件格式。

update1:我用

取代了FN的声明

fn <- sprintf("c:iris360/HW4_%03i.png", theta)

及其出现的地方用sprintf(“%03i”)替换IC,但仍然有相同的指定图像大小错误。
当我将系统命令运行到终端时,我仍然会遇到相同的错误,要求我指定图像大小。

Magick需要了解几件事(例如,图像大小,帧之间的延迟,使用的图像,目标文件名),以便将一堆PNG转换为GIF。请参阅

gif动画和动画元数据
r png gif magick
1个回答
0
投票

因此,您似乎需要更改 system("magick c:iris360\\HW4*.png c:iris.gif") to更喜欢的东西

system("magick -delay 10 -size 100x100 —loop 0 c:iris360\\HW4*.png c:iris.gif")

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.