简体   繁体   English

Totally stumpted - System.Runtime.InteropServices.ExternalException:'GDI +中发生了一般错误。'

[英]Totally stumpted - System.Runtime.InteropServices.ExternalException: 'A generic error occurred in GDI+.'

I've written a quick winform app that can take some entered text, generate images based on all the system fonts and then consolidate those images into a single image to give examples of the fonts. 我写了一个快速的winform应用程序,它可以输入一些输入文本,根据所有系统字体生成图像,然后将这些图像合并到一个图像中,以提供字体示例。 For ease, I've separated the two functions, one to generate the images and another to consolidate them so I can remove fonts I don't want in the single image. 为了方便起见,我将两个函数分开,一个用于生成图像,另一个用于合并它们,因此我可以删除单个图像中不需要的字体。 It was all working yesterday, but now when it comes to saving the consolidated image ("complete.save("consolidated.png");) it gives the useless GDI+ error. I've checked paths and access, all are fine and correct. Nothing is locking the image, so I'm totally at a loss as what is causing this. Any ideas? Code below 这一切都在昨天工作,但现在在保存整合图像时(“complete.save(”consolidated.png“);)它给出了无用的GDI +错误。我检查了路径和访问,一切都很好,正确什么都没有锁定图像,所以我完全不知道是什么造成了这个。任何想法?代码如下

StringBuilder sb = new StringBuilder();

        List<string> files = FileSystemUtilities.ListFiles("fonts");

        int height = 0;
        int width = 0;

        Bitmap test = new Bitmap(1000, 1000);
        Graphics gTest = Graphics.FromImage(test);

        Font font = new Font("Arial", 128);

        int numWidth = 0;

        int count = 1;

        foreach (var file in files)
        {
            sb.AppendFormat("{0}\r", FileSystemUtilities.GetFileName(file).Replace(".png", string.Empty));

            Bitmap bitmap = new Bitmap(file);

            height = height + bitmap.Height + 10;

            if (width < bitmap.Width)
            {
                width = bitmap.Width;
            }

            SizeF numSize = gTest.MeasureString(Convert.ToString(count), font);

            if (numWidth < numSize.Width)
            {
                numWidth = Convert.ToInt32(numSize.Width + 1);
            }

            bitmap.Dispose();

            count++;
        }

        test.Dispose();
        gTest.Dispose();

        numWidth = numWidth + 10;
        count = 1;
        Bitmap complete = new Bitmap(width + numWidth, height);
        Graphics g = Graphics.FromImage(complete);

        g.FillRectangle(Brushes.White, 0, 0, complete.Width, complete.Height);

        int y = 0;
        foreach (var file in files)
        {
            Bitmap bitmap = new Bitmap(file);

            g.DrawString(Convert.ToString(count) + ".", font, Brushes.Black, 0, y);

            g.DrawImage(bitmap, numWidth, y);

            y = y + bitmap.Height + 10;

            bitmap.Dispose();

            count++;
        }

        string filename = "consolidated.png";

        if (File.Exists(filename))
        {
            File.Delete(filename);
        }

        g.Dispose();
        complete.Save("consolidated.png");
        complete.Dispose();

        TextFileUtilities.WriteTextFile("consolidated.txt", sb.ToString());

Turns out it was due to excessive height... I couldn't see it. 事实证明这是由于身高过高......我看不到它。 Thank you for all that commented and helped me out. 感谢所有评论和帮助我的人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Runtime.InteropServices.ExternalException: &#39;GDI+ 中发生一般错误。&#39; - System.Runtime.InteropServices.ExternalException: 'A generic error occurred in GDI+.' System.Runtime.InteropServices.ExternalException:GDI +中发生一般错误 - System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+ 绘制图像时:System.Runtime.InteropServices.ExternalException:GDI中发生一般错误 - When drawing an image: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI ExternalException“GDI +中发生了一般错误。” - ExternalException “A generic error occurred in GDI+.” GDI+ System.Runtime.InteropServices.ExternalException On Image 调整大小和转换 - GDI+ System.Runtime.InteropServices.ExternalException On Image resize and conversion &#39;System.Runtime.InteropServices.ExternalException&#39; - 'System.Runtime.InteropServices.ExternalException' System.Runtime.InteropServices.ExternalException - System.Runtime.InteropServices.ExternalException GDI+System.Runtime.InteropServices.ExternalException HResult=0x80004005 Message=GDI+ 中发生一般错误 - A generic error occurred in GDI+System.Runtime.InteropServices.ExternalException HResult=0x80004005 Message=A generic error occurred in GDI+ &#39;System.Runtime.InteropServices.ExternalException&#39;发生在System.Drawing.dll中&#39; - 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll' 获取 System.Runtime.InteropServices.ExternalException! - getting System.Runtime.InteropServices.ExternalException!
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM