construct image from raw data ( sensor data) & display in windows Form

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello everyone,
The problem is:
I get some data from a vision chip, which has a resolution of 16x16 pixels. This data is in a 1D array ( first 16 elements - first row, next 16 elements - next row). Pixel has 8-bit depth. So I have a
byte array of length = 16*16.
I need to display this as ALPHA Image & also some colored shapes ( circle, rectangle etc..) on it.
For this, I created an Windows Form application in C# . I placed an
Panel control on it. Now I need to display the Image
described in the above line in the Panel control.
I have seen several examples over web, they talk about MemoryStream
to construct Image from byte array. These examples were not helpful.
1. How to construct ALPHA Image from the byte array ?
2. For drawing Image, which control is best ?
I tried the following :
<pre class="prettyprint" style=" Random r = new Random();
int width = 16;
int height = 16;
byte[] pixelValues = new byte[width * height];
for (int i = 0; i < pixelValues.Length; ++i)
{
//Just create random pixel values
pixelValues = (byte)r.Next(0, 255);
}[/code]
<pre class="prettyprint" style=" public void CreateBitmapFromBytes(byte[] pixelValues, int width, int height)
{
//Create an image that will hold the image data
Bitmap pic = new Bitmap(width, height, PixelFormat.Format16bppGrayScale);

//Get a reference to the images pixel data
Rectangle dimension = new Rectangle(0, 0, pic.Width, pic.Height);
BitmapData picData = pic.LockBits(dimension, ImageLockMode.ReadWrite, pic.PixelFormat);
IntPtr pixelStartAddress = picData.Scan0;

//Copy the pixel data into the bitmap structure
System.Runtime.InteropServices.Marshal.Copy(pixelValues, 0, pixelStartAddress, pixelValues.Length);

pic.UnlockBits(picData);
//pic.Save(@"D:mypic1.bmp", ImageFormat.Bmp);
image_panel.BackgroundImage = pic; // Just to see the Image, I set Panel BackgroundImage
}[/code]
The above code shows the following pattern on 400x400 size Panel
control always .
<img alt="ImageOnPanelControl" src="http://social.msdn.microsoft.com/Forums/getfile/212705 <br/>

Im expecting a display as shown in the following video (play video from
1:38 ) :<br/>
http://www.youtube.com/watch?feature=player_embedded&v=MItX9Pv5U4o" target="_blank YouTube video
The GUI shown in the video is created in Processing IDE environment. For the source
https://github.com/ArduEye/ArduEyeExamples/blob/master/FirstApp_StonymanUnoRocket_v1/FirstApp_StonymanUnoRocket_v1.ino" target="_blank
Click here<br/>
If your Idea is completely different from the sample code (my workaround), you are welcome. I need a best way to visualize the data.
Thank you.
<br/>
<br/>
<br/>
<br/>
<br/>

View the full article
 
Back
Top