I am trying to build a bitmap from a 2D array, with a low size just for testing. Even if I set the matrix properly (one pix black, one white), when I build the bitmap it seems like some interpolation filter is applied. How I can get just pixel values?
bool switchColor = false;
int width = 30;
int height = 15;
int stride = width * 4;
int[,] integers = new int[width, height];
int thres = 0;
for (int i = 0; i < width; ++i)
{
for (int j = 0; j < height; ++j)
{
if (switchColor)
{
switchColor = false;
thres = 0;
}
else
{
switchColor = true;
thres = 255;
}
byte[] bgra = new byte[] { (byte)(thres), (byte)(thres), (byte)(thres), 255 };
integers[i, j] = BitConverter.ToInt32(bgra, 0);
}
}
// Copy into bitmap
Bitmap bitmap;
unsafe
{
fixed (int* intPtr = &integers[0, 0])
{
bitmap = new Bitmap(width, height, stride, PixelFormat.Format32bppRgb, new IntPtr(intPtr));
pictureBox1.Image = bitmap;
}
}
I've got: