Developer technologies | Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have array of int or Color how to create bitmap?
if the bitmap width = 48 and height=12 then the array is Color
line 1 48 colors
line 2 48 colors
.....
how to create it to Bitmap?
A set of .NET Framework managed libraries for developing graphical user interfaces.
In Windows Forms (.NET), create a Bitmap and set its pixels from the array.
For an int[] of ARGB values (length = width * height):
int width = 48;
int height = 12;
int[] colors = new int[width * height];
// fill colors[y * width + x] with ARGB values
var bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int argb = colors[y * width + x];
bmp.SetPixel(x, y, Color.FromArgb(argb));
}
}
For a Color[] (length = width * height):
int width = 48;
int height = 12;
Color[] colors = new Color[width * height];
// fill colors[y * width + x]
var bmp = new Bitmap(width, height);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
bmp.SetPixel(x, y, colors[y * width + x]);
}
}
If performance is critical, use LockBits and copy the raw bytes instead of SetPixel, but the above is the simplest approach for a 48×12 image.
References: