【问题标题】:Why im getting big red X with white background in the pictureBox instead the animated gif?为什么我在pictureBox中得到带有白色背景的大红色X而不是动画gif?
【发布时间】:2012-07-03 03:12:57
【问题描述】:

我在硬盘上检查了动画 gif 的创建,我在 Internet Explorer 中打开它,它工作正常。

所以我不明白为什么我把这个白色配上大 x 红色。

我使用了断点,目前没有出现任何错误。

这个类中真正创建的gif动画是这行号175:

unfreez.MakeGIF(myGifList, previewFileName, 8, true);

动画 gif 是真实存在和创建的。在第 210 行中,我调用了将动画 gif 加载到图片框的函数:

pictureBoxImage(previewFileName);

这是我使用断点的pictureBoxImage函数,它没有显示任何错误:

public void pictureBoxImage(string pbImage)
{
    Image img2 = null;
    try
    {
        using (img = Image.FromFile(pbImage))
        {
            //get the old image thats loaded from the _memSt memorystream
            //and dispose it
            Image i = this.pictureBox1.Image;
            this.pictureBox1.Image = null;

            if (i != null)
                i.Dispose();

            //grab the old stream
            MemoryStream m = _memSt;

            //save the new image to this stream
            _memSt = new MemoryStream();
            img.Save(_memSt, System.Drawing.Imaging.ImageFormat.Gif);

            if (m != null)
                m.Dispose();

            //create our image to display
            img2 = Image.FromStream(_memSt);
        }

        if (img2 != null)
            pictureBox1.Image = img2;
        //label2.Text = numberOfFiles.ToString();
        //label6.Text = nameOfStartFile.ToString();
        //label4.Text = nameOfEndFile.ToString();
        //File.Delete(pbImage);
    }
    catch (Exception err)
    {
        Logger.Write("Animation Error >>>   " + err);
    }
}

不知道为什么?红色 x 和白色背景。

我没有将整个班级复制到这里,但如果需要,我会复制到这里,但动画 gif 制作得很好,并且可以在 Internet Explorer 上运行,所以班级正在工作,但由于某种原因,pictureBox 上的显示无法正常工作。

【问题讨论】:

  • 红x白底表示文件未找到……或者内存流无法转回gif。
  • 红叉是广义的“渲染失败”表示,我经常看到它与 DirectX 一起使用。至于具体原因……
  • 问题出在我做的顶级课程中:pictureBox1.Image.Dispose();当我将它标记为 // 所以它的工作。但是过了一段时间,我点击了按钮来制作动画 gif,它没有显示我在设计器中添加的默认图片框 1 图像。因此,出于某种原因,我每次调用类时都需要释放以处理图片框。因此,一方面我认为我需要在另一方面解决问题。

标签: c#


【解决方案1】:

Shawn Hargreaves 有一个出色而简洁的 writeup 是“厄运的大红色 X”。我发现它在处理 WinForm 组件突然显示红色“X”的一般情况下非常有用。

总结:

  • 这是由控件从OnPaint 事件中引发异常引起的。
  • 一旦被抛出,该控件将继续显示红色 X 并跳过射击 OnPaint.
  • 要进行调试,请将调试器设置为捕获公共语言运行时异常,然后执行您通常执行的任何操作以获取红色 X。调试器将在发生的位置停止,让您进行调查并希望找到解决方法防止它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-26
    • 1970-01-01
    • 2013-11-27
    • 1970-01-01
    • 2014-11-11
    相关资源
    最近更新 更多