I recently saw this error for the first time in previously working code, and don't follow why.
The exception is thrown on
BitmapSource.Create(width, height, 96, 96, PixelFormats.Bgr24, null, data, stride);
Here, width
is 1194, height
is 824, and stride
uses the equation ((width * 24 + 23) & ~23) / 8
, from this SO answer, which results in 3584 (which makes sense). The size of data
is 2 951 568, which appears to be correct (1194 * 824 * 3). These values are all taken from the debugger.
I've not been able to reproduce this, so can't identify the exact circumstances that caused it, but don't see how the exception makes sense from the arguments that were supplied.
Is it perhaps because I misunderstand what stride is supposed to be (and in the past, perhaps the resolution was always a multiple of the bit width)? The data
array does not have padding.