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]));
}
}
Good old compiler ... did you try his suggestion ?
Add this line in the top of your file :
using System.Drawing.Bitmap;
If you want more : check msdn.
By the way, you can right-click on Bitmap
and select Resolve
to do it. This is the easy way.
To save your image into a file, there is differents ways to do it. It depends of which platform you are. I think you should look in WriteableImageEx or here or here