IntPtr到Bitmap AccessViolationException

时间:2017-01-13 04:20:08

标签: c# bitmap aforge intptr

我有两个主题。一种是将当前视频帧复制到存储器指针列表。另一个线程正在将内存指针用作图像并扫描qr代码。我无法正确处理序列。如果我执行以下最小语句,它会在Crop()上抛出AccessViolationException。Apply()行:

var bytesPerLine = VideoWidth * 3;
var bytes = (uint)((VideoHeight) * bytesPerLine);
var memoryTarget = Marshal.AllocHGlobal((int)bytes);
CopyMemory(memoryTarget, memoryRenderl.CurrentFrame, bytes);
var image = new Bitmap(VideoWidth, VideoHeight, bytesPerLine, PixelFormat.Format24bppRgb, memoryTarget);
var cropped = new Crop(new Rectangle(0, 0, VideoWidth, VideoHeight)).Apply(image);

0 个答案:

没有答案