公司让我做个用directshow控制摄像头的小软件,现在基本功能都有了,就是内存老是报错!我都疯了,我也释放内存了呀!希望高手来指点一二!小弟感激不尽!
参考代码如下:
int hr = ibasicvideo.GetCurrentImage(ref buffersize, IntPtr.Zero);
DsError.ThrowExceptionForHR(hr);
currentImage = Marshal.AllocCoTaskMem(buffersize);
hr = ibasicvideo.GetCurrentImage(ref buffersize, currentImage);
string hresult = DsError.GetErrorText(hr);
DsError.ThrowExceptionForHR(hr);
BitmapInfoHeader structure = new BitmapInfoHeader();
Marshal.PtrToStructure(currentImage, structure);
IntPtr test = new IntPtr(currentImage.ToInt32() + 40);
bmp = new Bitmap(structure.Width, structure.Height, (structure.BitCount / 8) * structure.Width, System.Drawing.Imaging.PixelFormat.Format24bppRgb, test);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
Marshal.FreeCoTaskMem(currentImage);
Marshal.FreeBSTR(test);
现在就是不知道怎么把申请到的currentImage这块内存区域给释放掉!,我按Marshal.FreeCoTaskMem(currenImage);这个并不能释放掉,希望各位大侠多多指点
参考代码如下:
int hr = ibasicvideo.GetCurrentImage(ref buffersize, IntPtr.Zero);
DsError.ThrowExceptionForHR(hr);
currentImage = Marshal.AllocCoTaskMem(buffersize);
hr = ibasicvideo.GetCurrentImage(ref buffersize, currentImage);
string hresult = DsError.GetErrorText(hr);
DsError.ThrowExceptionForHR(hr);
BitmapInfoHeader structure = new BitmapInfoHeader();
Marshal.PtrToStructure(currentImage, structure);
IntPtr test = new IntPtr(currentImage.ToInt32() + 40);
bmp = new Bitmap(structure.Width, structure.Height, (structure.BitCount / 8) * structure.Width, System.Drawing.Imaging.PixelFormat.Format24bppRgb, test);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
Marshal.FreeCoTaskMem(currentImage);
Marshal.FreeBSTR(test);
现在就是不知道怎么把申请到的currentImage这块内存区域给释放掉!,我按Marshal.FreeCoTaskMem(currenImage);这个并不能释放掉,希望各位大侠多多指点
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货