2

I'm trying to use Bar Code Recognition software and need to iterate over all the frames in a tiff file. I am confused on several points: 1) What is a frame, why does it have a guid and why do I need to iterate over frames? I can't seem to find a lot of documentation.

2) The code throws an invalid parameter exception after one iteration. I'm not sure why; logically, i cannot exceed the frame count, so not sure how it could be an invalid parameter, assuming that is the problem.

System.Drawing.Image img = System.Drawing.Image.FromStream(mems);
Guid guid = img.FrameDimensionsList[0];
FrameDimension dimension = new FrameDimension(guid);
int totalFrame = img.GetFrameCount(dimension);

foreach(int i =0; i < totalFrame; i++)
{   
    img.SelectActiveFrame(dimension, i);
}
4

1 回答 1

4

帧通常表示同一图像文件中的多个图像。例如,动画 GIF 在时间维度上有几个帧。一个图标在分辨率维度上可能有几个帧(即不同分辨率的不同图像)。

例如,此代码显示动画 GIF 中的所有帧(在 LinqPad 中):

var image = Image.FromFile(path);
int frames = image.GetFrameCount(FrameDimension.Time);
for (int i = 0; i < frames; i++)
{
    image.SelectActiveFrame(FrameDimension.Time, i);
    image.Dump();
}

在您的代码中,您从 中获取第一个元素FrameDimensionList,但不知道它代表哪个维度。尝试FrameDimension.Page改用(假设您需要遍历“页面”维度)。

于 2012-08-08T01:06:18.790 回答