How to display a 1024 int value as a color for a bitmap

  • Thread starter Thread starter Btb4198
  • Start date Start date
B

Btb4198

Guest
I have an array of integers with values from 0-1024 that I can get from a mono camera. I need to turn this into a color to be used in a bitmap. how do I do this ?

public Bitmap InttoBitmap( int[] blob)
{
Bitmap bm = new Bitmap(keepWidth, keepHeight, System.Drawing.Imaging.PixelFormat.Format16bppRgb555);

int i = 0;
for (int x =0; x < keepWidth ; x++)
{
for( int y =0; y < keepHeight; y++ )
{
Color color = new Color();
color = Color.FromArgb(blob);
i++;
bm.SetPixel(x, y, color);
}

}
return bm;
}





Right, now I am only seeing the color blue, and I am getting back the value 84. I have code to draw a box on my video and display the values in that box, and I am just seeing 84 back. not 1024




public double[,] imageToByteArray(Bitmap _image)
{
Bitmap b = new Bitmap(_image);

BitmapData bData = b.LockBits(new Rectangle(0, 0, _image.Width, _image.Height), ImageLockMode.ReadWrite, b.PixelFormat);

/* GetBitsPerPixel just does a switch on the PixelFormat and returns the number */
byte bitsPerPixel = GetBitsPerPixel(bData.PixelFormat);

/*the size of the image in bytes */
int size = bData.Stride * bData.Height;

/*Allocate buffer for image*/
byte[] data = new byte[size];
double[,] returndata = new double[_image.Height, _image.Width];
/*This overload copies data of /size/ into /data/ from location specified (/Scan0/)*/
System.Runtime.InteropServices.Marshal.Copy(bData.Scan0, data, 0, size);
int i = 0;
for (int y = 0; y < _image.Height; y++)
{

for (int x = 0; x < _image.Width; x++)
{

double magnitude = 1 / 3d * (data + data[i + 1] + data[i + 2]);

returndata[y, x] = magnitude;
i += bitsPerPixel / 8;
}
}

return returndata;

}

Continue reading...
 
Back
Top