I\'m using locked bitmaps a lot recently, and I keep getting \"attempted to access invalid memory\" errors. This is mostly because the bitmap has been moved in memory. Some
In your case an attempted to access invalid memory
error is most probably caused by invalid memory allocation which you are doing in the unsafe part of code, e.g allocated array is smaller than number of pixels you are trying to put in that.
There is also no need to think about pinning the objects unless your image data is less than 85000 Bytes as only objects less than 85K will be moved in memory.
Another story would be if you pass the object to unmanaged code, for example in the c++ library for faster processing. In this case your exception is very possible if the passed image gets out of scope and will be garbage collected. In this case you can use GCHandle.Alloc(imageArray,GCHandleType.Pinned);
and than call Free if you do not need it any longer.