Date: 01/26/06 (C Sharp) Keywords: no keywords protected unsafe bool getBinaryAt(int x, int y, BitmapInfo img) { fixed (byte* scan0 = &img.pixelData[0]) { byte pval = 0; byte* pos = scan0 + y * img.Stride + x * getByteSize(img.Format); pval = (byte)((*pos + *(pos + 1) + *(pos + 3)) / 3); return (pval > THRESH); } } The problem: "AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt." You know what I hate more than anything right now? AccessViolationExceptions. I apparently don't know what I'm doing when it comes to working with images. Edit: Now with a question!! Is accessing an array element via pointer arithmetic faster than accessing it using [] syntax in C#? I ask because I'm trying this about 3 million times per second.
|