试图遍历一个System.Drawing.Image对象帧,将引发无效的参数异常

编程入门 行业动态 更新时间:2024-10-13 16:22:44
本文介绍了试图遍历一个System.Drawing.Image对象帧,将引发无效的参数异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图用吧code识别软件,并需要遍历所有帧中的TIFF文件。我很困惑的几个要点: 1)什么是一个框架,为什么它有一个GUID,为什么我需要遍历框架?我似乎无法找到大量的文档资料。

2)code投一次迭代后无效的参数异常。我不知道为什么;从逻辑上讲,我不能超过帧数,所以不知道它怎么可能是一个无效的参数,假设这就是问题所在。

为System.Drawing.Image IMG = System.Drawing.Image.FromStream(MEMS); 的Guid GUID = img.FrameDimensionsList [0]; FrameDimension尺寸=新FrameDimension(GUID); INT totalFrame = img.GetFrameCount(尺寸); 的foreach(INT I = 0; I< totalFrame;我++) {     img.SelectActiveFrame(尺寸,I); }

解决方案

帧通常重相同的图像文件内的present多个图像。例如,动画GIF具有沿着时间维度几个帧。一个图标可能沿着分辨率尺寸(即不同的图像不同的分辨率),多帧图像。

例如,这code显示GIF动画的所有帧(在LinqPad):

变种形象= Image.FromFile(路径); 诠释帧= image.GetFrameCount(FrameDimension.Time); 的for(int i = 0; I<帧;我++) {     image.SelectActiveFrame(FrameDimension.Time,我);     image.Dump(); }

在你的code,你正在做的 FrameDimensionList 的第一个元素,不知道哪个维度它重新presents。尝试使用 FrameDimension.Page ,而不是(假设你需要遍历页尺寸)。

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

解决方案

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).

更多推荐

试图遍历一个System.Drawing.Image对象帧,将引发无效的参数异常

本文发布于:2023-11-12 11:01:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581302.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:遍历   异常   对象   参数   Image

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!