C# Draw on image using unsafe pointers
<p>I'm trying to set few pixels in a bitmap using unsafe pointer access(for performance boost)-this is my code:</p>

<pre><code> private unsafe void DrawImage(Bitmap bmp1) 
 {
  BitmapData bmData = bmp1.LockBits(new Rectangle(0, 0, bmp1.Width, bmp1.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp1.PixelFormat);
  IntPtr scan0 = bmData.Scan0;
  int stride = bmData.Stride;
  int x = 200;
  int y = 400;

  for (; y &lt; 600; y++) {
   byte * p = (byte * ) scan0.ToPointer();
   p += y * stride + x * 4;


   for (; x &lt; 900; x++) {

    p[0] = 0; //blue
    p[1] = 0; //green
    p[2] = 255; //red              
    p += 4;
   }

  }

  bmp1.UnlockBits(bmData);

 }
</code></pre>

<p>As you can see,i'm trying to set a block (to red color) from  <strong>y=400</strong> to <strong>y=600</strong> , and <strong>x=200</strong> to <strong>x=900</strong>.
On every interation of the outer loop i advance the pointer to the desired address ,but i'm getting only a "thin" horizontal line of red pixels...which indicated that somthing is wrong with the <code>y</code> address..i can't get why.
<code>
p += y * stride + x * 4;</code>-this is how i advance the pointer everytime... did i miss something?</p>

<p>i hope my question was clear.
Thanks in advance.</p>