使用Image.Save时(C#泛型GDI +错误) [英] C# Generic GDI+ Error when using Image.Save()

查看:729
本文介绍了使用Image.Save时(C#泛型GDI +错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中成像的相对新手。这是一个很长的是一个成员时间后,我对这款主板的第一个问题。我希望这能帮助我通过这个棘手的情况下得到的。

I am a relative novice with imaging in C#. This is my first question on this board after a very long time of being a member. I hope it can help me get through this tricky scenario.

我需要阅读多页TIFF的内容(帧),节约每一个成一个列表,最后返回它,然后用它做一些工作。

I need to read the contents (frames) of a Multi Page TIFF, saving each one into a List and finally returning it to then do some work with it.

继承人我到目前为止的代码

Heres my code so far

public static  List<Image> GetAllPages(string file)
{
    images = new List<Image>();
    using (Image img = Image.FromFile(file))
    {
        try
        {
            for (int i = 0; i < img.GetFrameCount(FrameDimension.Page); i++)
            {
                img.SelectActiveFrame(FrameDimension.Page, i);
                MemoryStream byteStream = new MemoryStream();
                img.Save(byteStream, ImageFormat.Tiff);
                images.Add(Image.FromStream(byteStream));
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
    return images;
}

重要提示 - 这实际上就像一个魅力时,在Windows 7上执行但是,试图在Windows XP相同的,当我得到了seemedly知名的通用GDI +错误。

IMPORTANT - This actually works like a charm when executing on Windows 7. However, when attempting the same on a Windows XP I get the seemedly well known Generic GDI+ error.

有什么明显我是缺少在这里?如果没有,会有回图像的列表,从多页TIFF提取任何其他更有效的方法?

Is there anything obvious i am missing here? If not, would there be any other, more efficient way to return a list of images, extracted from a multi page tiff?

我将不胜感激任何帮助,任何人都可以给

I would greatly appreciate any help anyone can give.

推荐答案

有很多由Hans帕桑特注释信息有益2位。首先,TIFF格式支持无数子类型和变化并非所有的由GDI +的支持。
二,GDI +是XP后好转,但不是无处不在。

There are 2 useful bits of information in the comment by Hans Passant. First, the TIFF format supports countless sub-types and variations not all of which are supported by GDI+. Second, GDI+ was improved after XP, but not everywhere.

您的代码不会在Windows XP和Windows 7的工作,但只有正确输入TIFF文件。

Your code does work on both Windows XP and Windows 7, but only with the right input TIFF files.

我测试了它使用.NET 2.0和.NET 4.0的方案有2个输入文件。所述第一文件有6页,所有这些都编码LZW压缩。此文件的工作在Windows 7和XP两个。

I tested it using .NET 2.0 and .NET 4.0 programs with 2 input files. The first file had 6 pages, all of which were encoded with LZW compression. This file worked on both Windows 7 and XP.

第二个文件有11页与11种不同的编码。在Windows XP中,只有7页出的11个正确加载。
在Windows 7中,更少的网页的工作,但特别是JPEG压缩工作正常,虽然它未能在XP下。

The second file had 11 pages with 11 different types of encoding. On Windows XP, only 7 pages out of 11 were loaded correctly. On Windows 7, even fewer pages worked, but the JPEG compression in particular worked correctly although it failed under XP.

Windows 8.1中的情况比这两个更好管理要正确地进行负载8页

Windows 8.1 fared better than both and managed to load 8 pages correctly.

您可以找到这些文件连同这个页面上使用的压缩类型的列表:
http://support.leadtools.com/CS/forums/44475/ShowPost.aspx

You can find the files along with a list of compression types used on this page: http://support.leadtools.com/CS/forums/44475/ShowPost.aspx

当然还有其他的TIFF子类型,其中大部分是不由GDI支持+本身,但这些11是比较常见的格式中。

Of course there are other TIFF sub-types, most of which are not supported by GDI+ natively, but these 11 are among the more common formats.

这给我们留下了让你的文件,在Windows XP上运行的问题。由于他们在Windows 7上运行,有一个很大的可能性,你有一个TIF子类型,它在Windows 7上工作,但由于JPEG压缩不是XP的这样。如果是这样的情况下,单独的.NET将是不够的,你可能需要使用专用的成像或TIFF库加载此类文件。

This leaves us with the problem of getting your files to work on Windows XP. Since they work on Windows 7, there's a strong possibility you have a TIF sub-type that works on Windows 7 but not XP such as JPEG compression. If that's the case, .NET alone will not be enough and you might have to use a dedicated imaging or TIFF library to load such files.

这篇关于使用Image.Save时(C#泛型GDI +错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆