Event on GIF reset
7 ビュー (過去 30 日間)
Currently devloping an app with appdesiner.
I have an image object, which is playing a GIF.
I would like to collect a timestamp each time the gif resets, or plays a sequence of frames fully.
Alternatively, is there a way of collecting and index for the current frame being displayed?
This is the line that begins displaying the gif:
app.Image.ImageSource = 'C:\Users\user\Desktop\GifFolder\4_7_8.gif';
Adam Danz 2022 年 8 月 3 日
編集済み: Adam Danz 2022 年 8 月 3 日
Without knowing the end goal, I'm not certain this will be useful but it sounds like what you're looking for can be computed or at least approximated by looking at the GIF file properties.
The first section below shows how to compute the duration of a GIF file but rendering delay may add to the actual cycle duration of a GIF file.
The second section below shows how to pull apart a GIF into single frame data but if you're going to match a frame to a template such as frame 1, that will surely add processing delays as well.
Getting frame count and frame delay from a GIF file
The number of frames of a GIF and the DelayTime for each frame can be extracted using imfinfo. Using this example GIF from Wiki (also attached)
file = 'Rotating_earth_(large).gif';
info = imfinfo(file)
info is a structure containing information about each frame of the GIF.
% Count number of frames
nFrames = numel(info)
% Extract delay from each frame (in 1/100 sec)
delay = [info.DelayTime]
% Compute total duration of GIF in seconds
totDur = sum(delay/100)
Analyzing a GIF frame-by-frame
If you want to go deeper and analyze frames, read in the GIF frames using imread
[gifImage, map] = imread(file, 'Frames', 'all');
Or, if it's easier to work with a movie rather than a GIF, you could convert the GIF to an AVI or another format. See gif2avi from the File Exchange, be sure to use the native GIF frame rate.