unsafe
{
Size s = getVideoSize(mediaType);
int bmpinfoheaderSize = 40; //equals to sizeof(CommonClasses.BITMAPINFOHEADER); //get size for buffer
int bufferSize = (((s.Width * s.Height) * 24) / 8) + bmpinfoheaderSize; //equals to mediaDet.GetBitmapBits(0d, ref bufferSize, ref *buffer, target.Width, target.Height); //allocates enough memory to store the frame
IntPtr frameBuffer = System.Runtime.InteropServices.Marshal.AllocHGlobal(bufferSize);
byte* frameBuffer2 = (byte*)frameBuffer.ToPointer(); //gets bitmap, save in frameBuffer2
mediaDet.GetBitmapBits(streamLength * percentagePosition, ref bufferSize, ref *frameBuffer2, target.Width, target.Height); //now in buffer2 we have a BITMAPINFOHEADER structure followed by the DIB bits Bitmap bmp = new Bitmap(target.Width, target.Height, target.Width * 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, new IntPtr(frameBuffer2 + bmpinfoheaderSize)); bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
System.Runtime.InteropServices.Marshal.FreeHGlobal(frameBuffer); return bmp;
}忽然报错“不安全代码只会在使用 /unsafe 编译的情况下出现”请问是什么原因?
解决方案 »
- 求金额的正则表达式!!!急用!!!
- 如何通过枚举类名和其中一项,来获得真正的对象
- 怎样创建一个无窗口的后台运行程序?
- getmethod 方法如何使用
- 重装系统后,发现再也装不了VS.NET啦
- 怎么会有值
- 关于visual stadio 2005的datagridview
- 一个关于Form关闭的问题!!谢谢!!!!!
- 急问在datagrid中用DataFormatString="{0:d}"如何规定日期的显示格式为dd/mm/yyyy!!!!!!
- C#中 BeginAcceptSocket 与BeginAcceptTcpClient 这两个方法有什么不同
- 投票提交问题
- 动画的问题,实现多个物体一起动画
C# 编译器选项
/unsafe
备注
/unsafe 选项允许编译使用 unsafe 关键字的代码。
在 Visual Studio 开发环境中设置此编译器选项
打开此项目的“属性页”对话框。有关详细信息,请参见设置 Visual C# 项目属性。
单击“配置属性”文件夹。
单击“生成”属性页。
修改“允许不安全代码块”属性。