I've got a bitmap that's 827852 pixels wide by 1 pixel high in a Bitmap object.
When converting the bitmap to a BitmapSource for rendering in WPF, the following artifacts appear in the UI:

The black portion in the middle is not in the original bitmap, and the yellow parts should be green, something like this:

By plain old trial and error I've determined that the problem appears when the original bitmap is wider than 524287 pixels. If it's 524288 or larger, I get rendering artifacts after converting it to a BitmapSource. 524287 is 0x7FFFF, which seems to indicate a overflow, but I'm unsure of where.
I'm using the following conversion method:
public BitmapSource Convert(Bitmap bitmap)
{
    var bitmapData = bitmap.LockBits(
        new Rectangle(0, 0, bitmap.Width, bitmap.Height),
        System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
    var bitmapSource = BitmapSource.Create(
        bitmapData.Width, bitmapData.Height, 96, 96, PixelFormats.Bgr24, null,
        bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, bitmapData.Stride);
    bitmap.UnlockBits(bitmapData);
    return bitmapSource;
}
taken from fast converting Bitmap to BitmapSource wpf
Any ideas where the issue occurs and how to work around it? I'm leaning towards rescaling the bitmap to be <524288 pixels manually.