Slanted Bitmap, Schrittberechnung für RGB565 C #

Einige meiner resultierenden Bilder sind schief, andere nicht.

Erwartetes Ergebnis: (529 x 22)

Tatsächliches Ergebnis: (529 x 22)

Beachten Sie die unterschiedlichen Bildgrößen, dies sind Screenshots. Sie sind beide 529x22.

Der Code, den ich verwende, stammt gerade von einer Antwort auf eine Frage hier bei SO.

// some other method
byte[] pixels = new byte[size - 16];
Array.Copy(this.data, offset, pixels, 0, pixels.Length);
this.ByteToImage(w, h, pixels);

// builds the pixels to a image
private Bitmap ByteToImage(int w, int h, byte[] pixels)
{
    var bmp = new Bitmap(w, h, PixelFormat.Format16bppRgb565);

    var BoundsRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
    BitmapData bmpData = bmp.LockBits(BoundsRect,
                                    ImageLockMode.WriteOnly,
                                    bmp.PixelFormat);

    // bytes => not using this because it gives error
    // eg. pixel.Length = 16032, bytes = 16064
    int bytes = bmpData.Stride * bmp.Height;

    Marshal.Copy(pixels, 0, bmpData.Scan0, pixels.Length);
    bmp.UnlockBits(bmpData);

    return bmp;
}

Ich bin verwirrt, weil manche ok funktionieren, nicht schief. Aber andere sind geneigt. Was habe ich verpasst

Aktualisiere

Wie in den Kommentaren und Antworten angegeben, ist das Problem, wie ich Schritt berechne. Ich bin immer noch verwirrt, wie es geht, aber ich habe es versucht:

public static void RemovePadding(this Bitmap bitmap)
{
    int bytesPerPixel = Image.GetPixelFormatSize(bitmap.PixelFormat) / 8;

    BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
    var pixels = new byte[bitmapData.Width * bitmapData.Height * bytesPerPixel];

    for (int row = 0; row < bitmapData.Height; row++)
    {
        var dataBeginPointer = IntPtr.Add(bitmapData.Scan0, row * bitmapData.Stride);
        Marshal.Copy(dataBeginPointer, pixels, row * bitmapData.Width * bytesPerPixel, bitmapData.Width * bytesPerPixel);
    }

    Marshal.Copy(pixels, 0, bitmapData.Scan0, pixels.Length);
    bitmap.UnlockBits(bitmapData);
}

Aber das Ergebnis ist (schräger):

Antworten auf die Frage(4)

Ihre Antwort auf die Frage