BitmapData vs Image<,>.Data when accessing to pixel value - performance
<p>I'm working on an tool for image processing (C#, using a EmguCV)
I need to get best performance on single operations on pixels.</p>

<p>I have read a lot of threads about <code>LockBit()</code> and copying a values from pointer to array of byte as a BEST method (when performance is priority) to get/set pixel value.</p>

<p>I found some implementations like this:
<a href="http://www.codeproject.com/Tips/240428/Work-with-bitmap-faster-with-Csharp" rel="nofollow">http://www.codeproject.com/Tips/240428/Work-with-bitmap-faster-with-Csharp</a></p>

<p>And I have compared it to much simpler method:</p>

<pre><code>Image&lt;Bgr, byte&gt; image = new Image&lt;Bgr, byte&gt;(Bitmap);
byte[,,] data = image.Data;

//And then get r channel like:
byte rChannel = data[y,x,0];

//And set r channel like:
data[y,x,0] = color.R;
</code></pre>

<p>So, I have used a implementation from link above but i cut out a creating <code>Color</code> like <code>Color.FromArgb(r, g, b);</code> and assume that image depth = 24, just to optimilize performance (I'm returning a 1D array of byte as a color)</p>

<p>My results (Image 2048x2048 - 4194304 operations of comparing color of pixel with <code>Color.White</code> - done 3 times):</p>

<pre><code>Via `LockBit()` and pointer method:
00:00:00.7971876
00:00:00.7569262
00:00:00.7693977

Via `Image&lt;,&gt;.Data` method:
00:00:00.7957318
00:00:00.8136698
00:00:00.8010817
</code></pre>

<p>I dont see any significant performance difference between a unsafe <code>LockBits()</code> and pointer method and pretty clear and easy <code>Image&lt;,&gt;.Data</code> one. </p>

<p>Can someone explain me why the <code>LockBits()/Pointer</code> method is called a super fast? Maybe I'm missing something (as I said - i have used a implementation from link above).</p>