c# - TIF 文件中 C# 中的 OutofMemory 错误

标签 c#

当扫描超过 1366 个文件时会报错 代码计算所选文件夹中的 tif 文件 代码:

 int mergeTiffPages(string[] path)
    {
        Cursor.Current = Cursors.WaitCursor;
        string[] sa = path;
        int frame = 0;
        Bitmap bitmap;
        int count = 0 ;
        foreach (string s in sa)
        {
            {
                try
                {
                    bitmap = (Bitmap)Image.FromFile(s);//Its will raise an error OutOf Memory
                    if (bitmap != null)
                    {
                        count = bitmap.GetFrameCount(FrameDimension.Page);
                        frame += count;
                        bitmap = null;
                        count = 0;
                    }
                }
                catch(Exception ex)
                {
                    MessageBox.Show("Not TIFF image file. please select the folder in which tif file is available", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        cntval.Text = frame.ToString();
        Cursor.Current = Cursors.Default;
        return 1;

    }

path函数中设置所有图片文件的数组

Error:OutOfMemory

最佳答案

使用这个:

 using (bitmap = (Bitmap)Image.FromFile(s))
                        {

                               ...                          
                        }

关于c# - TIF 文件中 C# 中的 OutofMemory 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20650050/

相关文章:

javascript - Kendo Grid 中的日期字段在 Controller 上为空

C# 隐藏调整大小光标

c# - Vs2019 无法运行 NUnit 测试 - 'testhost.x86.exe' 问题

c# - 我应该如何创建回调

c# - 在 Xamarin.Forms 中使用带有嵌入图像的图标属性

c# - 如何将参数传递给 Activator.CreateInstance<T>()

c# - ClickOnce 部署应用程序的 Prism 架构注意事项

c# - 仅从 DataGridView 的特定列获取文本

c# - 如何在后台线程中创建 WPF 控件?

c# - 进程调试管理器 (PDM) 安全问题