visual-studio-2012 - Visual Studio 2012 - vshost32-clr2.exe 已停止工作

标签 visual-studio-2012 bmp lockbits vshost32

我正在使用 Visual Studio 2012 在 C# 中创建 WinForm 应用程序,但在调试时出现错误:

vshost32-clr2.exe has stopped working

我已经搜索过,但大多数结果都是针对 Visual Studio 2010 及更低版本的,我得到了类似的解决方案,但我认为它不适用于 Visual Studio 2012:

Properties -> Debug -> Enable unmanaged code debugging

来源:vshost32.exe crash when calling unmanaged DLL

其他详细信息:

  • 我的项目不使用任何 DLL。

  • 就我的项目进展而言,它仅在宽度为 17 时发生。

我使用以下代码:

        Bitmap tmp_bitmap = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

        Rectangle rect = new Rectangle(0, 0, 16, tmp_bitmap.Height);
        System.Drawing.Imaging.BitmapData bmpData =
            tmp_bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
            tmp_bitmap.PixelFormat);

        unsafe
        {
            // Get address of first pixel on bitmap.
            byte* ptr = (byte*)bmpData.Scan0;

            int bytes = Width * Height * 3; //124830 [Total Length from 190x219 24 Bit Bitmap]
            int b;  // Individual Byte

            for (int i = 0; i < bytes; i++)
            {
                _ms.Position = EndOffset - i;  // Change the fs' Position
                b = _ms.ReadByte();              // Reads one byte from its position

                *ptr = Convert.ToByte(b);
                ptr++;

                // fix width is odd bug.
                if (Width % 4 != 0)
                    if ((i + 1) % (Width * 3) == 0 && (i + 1) * 3 % Width < Width - 1)
                    {
                        ptr += 2;
                    }
            }
                // Unlock the bits.
            tmp_bitmap.UnlockBits(bmpData);
        }

我认为发布我的代码是必要的,因为它只有在我的方法设置了这样的值时才会发生。

我希望你能帮我解决这个问题。 非常感谢您!

最佳答案

不确定这是否是同一个问题,但我有一个非常相似的问题,当我在项目/属性的调试部分下取消选中“启用 Visual Studio 托管进程”时,该问题已解决(消失)。我还启用了 native 代码调试。

关于visual-studio-2012 - Visual Studio 2012 - vshost32-clr2.exe 已停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16523003/

相关文章:

c# - 以这种方式使用锁位复制位图区域是否安全(双关语)?

Android:在 NFC NTAG213 上重置动态锁时出错(28h)

c++ - 如何将 Intel C++ 编译器 2015 与全新安装的 Visual Studio 2012 集成

visual-studio-2012 - 如何更改 Visual Studio 2012 Express 项目模板?

visual-studio-2012 - 在 Visual Studio 中阻止自动格式化忽略命令

c# - 如何在Bitmap header中存储ASCII信息?

c - 位图最大尺寸

C# asp.net 日历控件从顶部移动显示

c - 从 BMP 文件读取到 C 中的 BMP 头结构

C# 如何将我的 getPixel/SetPixel 颜色处理转换为 Lockbits?