So I'm using System.Drawing Bitmap implementation. It looks like when setting format to PixelFormat.Format24bppRgb its actually interpreting it as 24 Bgr and not Rgb
latestImage = new Bitmap(bitmap.Width, bitmap.Height, bitmap.Stride, PixelFormat.Format24bppRgb, bitmap.Scan0);
for (int x = 0; x < _latestImage.Width; x++)
{
for (int y = 0; y < _latestImage.Height; y++)
{
var c = _latestImage.GetPixel(x, y);
byte r = Marshal.ReadByte((bitmap.Scan0 + (x * 3) + 0) + (y * bitmap.Stride));
byte g = Marshal.ReadByte((bitmap.Scan0 + (x * 3) + 1) + (y * bitmap.Stride));
byte b = Marshal.ReadByte((bitmap.Scan0 + (x * 3) + 2) + (y * bitmap.Stride));
_latestImage.SetPixel(x, y, System.Drawing.Color.FromArgb(r, g, b));
}
}
_latestImage.Save(temp3, ImageFormat.Jpeg);
vs
_latestImage = new Bitmap(bitmap.Width, bitmap.Height, bitmap.Stride, PixelFormat.Format24bppRgb, bitmap.Scan0);
_latestImage.Save(temp3, ImageFormat.Jpeg);
In the first example were I loop over everything and manually set the colors it works fine but takes for ever. In the second one the red and blue colors are swapped in the image.
Am I crazy or is the .net implementation wrong here?
I've tried different formats but the rest are even worse. Been looking for another library to handle my Bitmap data but haven't found a solution yet.