I am trying to create a BitMap
from a string array of pixel color values. The array contains 76800 elements (320 x 240) which have the pixels in decimal format (e.g. "11452343").
I am trying to use this function to create my BitMap
var b = new Bitmap(320, 240, PixelFormat.Format8bppIndexed);
var ncp = b.Palette;
for (int i = 0; i < 256; i++)
ncp.Entries[i] = Color.FromArgb(255, i, i, i);
b.Palette = ncp;
var BoundsRect = new Rectangle(0, 0, 320, 240);
var bmpData = b.LockBits(BoundsRect, ImageLockMode.WriteOnly, b.PixelFormat);
var ptr = bmpData.Scan0;
var bytes = bmpData.Stride * b.Height;
var rgbValues = new byte[bytes];
for (var i = 0; i < pixelArray.Length; i++)
{
// ISSUE OCCURS HERE
rgbValues[i] = byte.Parse(pixelArray[i]);
}
Marshal.Copy(rgbValues, 0, ptr, bytes);
b.UnlockBits(bmpData);
My issue occurs inside the for
loop where I try to convert the decimal value to a byte value to add to the rgbValues
array. How can I convert that decimal color to a byte value to add to the array?