Trying to iterate over the frames in a System.Drawing.Image, throws invalid parameter exception

ⅰ亾dé卋堺 提交于 2019-12-24 03:44:14

问题


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);
}

回答1:


Frames typically represent several images within the same image file. For instance, an animated GIF has several frames along the time dimension. An icon might have several frames along the resolution dimension (i.e. distinct images for different resolutions).

For instance, this code displays all frames in an animated GIF (in 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();
}

In your code, you're taking the first element from FrameDimensionList, without knowing which dimension it represents. Try using FrameDimension.Page instead (assuming you need to iterate over the "page" dimension).



来源:https://stackoverflow.com/questions/11856210/trying-to-iterate-over-the-frames-in-a-system-drawing-image-throws-invalid-para

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!