title: stride and padding of an image
body: <p>I wanted to use <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ee690291%28v=vs.85%29.aspx" rel="nofollow noreferrer">CreateBitmapFromMemory</a> method, and its requires the stride as an input. and this stride confused me.</p>
  <blockquote>
  <p>cbStride [in]</p>
  <p>Type: UINT</p>
  <p>The number of bytes between successive scanlines in pbBuffer.</p>
  </blockquote>
  <p>and <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa473780(v=vs.85).aspx" rel="nofollow noreferrer">here</a> it says: stride = image width + padding</p>
  <ol>
  <li>Why do we need these extra space(padding). why dont just image width.</li>
  </ol>
  <hr />
  <p>This is how calculate the stride right?</p>
  <pre><code>    lWidthByte = (lWidth * bits + 7) / 8;
  </code></pre>
  <p>lWidth→pixel count</p>
  <p>bits→bits per pixel</p>
  <p>I suppuse deviding by 8 is for convert to byte. but,</p>
  <ol start="2">
  <li>What  is (+7) doing here?</li>
  </ol>
  <hr />
  <p>and finally</p>
  <pre><code>    cbStride =((lWidthByte + 3) / 4) * 4;
  </code></pre>
  <ol start="3">
  <li>Whats going on here? (why not cbStride = lWidthByte)</li>
  </ol>
  <p>Please help me to clear these.</p>