Microsoft Dev Blogs

The case of the image that came out horribly slanted: Negative stride

thumbnail

Negative Stride in Bitmaps

  • Definition: Negative stride in a bitmap indicates that the next row of pixels is stored before the current row of pixels in memory. This can be seen in bottom-up DIB sections where the first row in memory represents the bottom row of the bitmap.

  • Handling Negative Stride:

    • For converting a bitmap with negative stride to one with positive stride or vice versa:
      • Find the last row of the bitmap by adding (height - 1) x stride to the first row.
      • Use this last row as the first row of the corresponding bitmap with the opposite sign stride.
  • Visual Representation:

    • Diagrams showcasing the layout of bitmap pixels in memory with negative stride.
  • Implementation:

    • Add support for negative stride to converters for graphics frameworks that do support it, even though Direct2D bitmaps have unsigned stride values.