I would like to generate a two dimensional array of pixels and then save it in .bmp file. I've read about Bitmaps, but I don't fully understand how to convert 2D arrays of Integer to Bitmap image.
That's what I've already found and tried to make
// Create array of integers
int width = 1024;
int height = 768;
int[] integers = new int[width * height];
// Fill array with random values
Random random = new Random();
for (int i = 0; i < integers.Length; ++i)
{
integers[i] = random.Next(Int32.MaxValue);
}
// Copy into bitmap
Bitmap bitmap;
unsafe
{
fixed (int* intPtr = &integers[0])
{
bitmap = new Bitmap(width, height, width, PixelFormat.Format32bppRgb, new IntPtr(&integers[0]));
}
}
However I still don't understand this part
// Copy into bitmap
Bitmap bitmap;
unsafe
{
fixed (int* intPtr = &integers[0])
{
bitmap = new Bitmap(width, height, width, PixelFormat.Format32bppRgb, new IntPtr(&integers[0]));
}
}
- The compiler says The type or namespace name 'Bitmap' could not be found (are you missing a using directive or an assembly reference?)
- How can I put it into the bmp file?