我正在使用Visual Studio 2012和C#创建一个WinForm应用程序,调试时出现了错误:
vshost32-clr2.exe has stopped working
我已经搜索过了,但大部分结果都是针对Visual Studio 2010及以下版本的,并且我得到了类似的解决方案,我认为这不适用于Visual Studio 2012:
Properties -> Debug -> Enable unmanaged code debugging
附加细节:
我的项目没有使用任何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);
}
我认为发布我的代码是必要的,因为只有在将此值设置为我的方法时才会出现此问题。
我希望你能帮助我解决这个问题。 非常感谢您提前的帮助!