我可以 运行 Gif 用 c 程序吗?

Can I run Gif with c program?

我知道我可以显示.png 文件,所以我认为我可以显示.gif 文件。 我正在使用 opencv,我将发送用于显示 .png 文件的代码(当您将目录更改为有效目录时,该代码有效)。

#include <stdio.h>
#include <opencv2\highgui\highgui_c.h>
int main(void)
{
int i;
cvNamedWindow("Display window", CV_WINDOW_AUTOSIZE); //create a window
    //create an image
IplImage* image = cvLoadImage("C:\c1.png", 1); //change to a valid directory
if (!image)//The image is empty.
{
printf("could not open image\n");
}
else
{
cvShowImage("Display window", image);
cvWaitKey(0);
system("pause");
cvReleaseImage(&image);
}
return 0;
}

不幸的是,opencv 中没有直接的 gif 支持。

cv2.imread(image.gif) 不是 possible.But 还有很多其他插入 GIF 的方法

您可以使用 moviepy 模块来实现

Link for moviepy

这是一个例子: 将视频摘录转换为 GIF

importing moviepy module

from moviepy.editor import *

Then a video file is opened and selected the part between 1’22.65 (1 minute 22.65 seconds) and 1’23.2, reduce its size (to 30% of the original) and save it as a GIF

clip = (VideoFileClip("frozen_trailer.mp4").subclip((1,22.65),(1,23.2)).resize(0.3))
clip.write_gif("use_your_head.gif")