0

I have two threads. One is copying the current video frame to a memory pointer list. The other thread is consuming the memory pointers as images and scanning for qr codes. I'm having trouble getting the sequence right. If I do the following minimal statements it's throwing AccessViolationException on the Crop().Apply() line:

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);
cbr
  • 12,563
  • 3
  • 38
  • 63
Sean
  • 51
  • 1
  • 4
  • Difficult to say when I don't know what the Crop method does. – H.G. Sandhagen Jan 13 '17 at 05:48
  • The bytes per line, or stride, is not necessarily equal to image width times the number of bytes per pixel. The number must be a multiple of four. Look [here](http://stackoverflow.com/a/2186454/650012) for a formula to correctly calculate the stride/bytes per line. – Anders Gustafsson Jan 13 '17 at 07:18

0 Answers0