views:

23

answers:

2

Hi,

i have a 672*472*3 size array of type double(r-g-b channels of an image). the values at each pixel position range from 0.000 to 5.0000. i need to show the data as an image on a picturebox. how can i do this in c#.

+1  A: 

You could create a new Bitmap object and set the pixels according to the data in your array with SetPixel()

See here:

http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.setpixel.aspx

You will have to iterate over the array with two loops and translate the 0-5 range to 0-255 to create a color object.

Then you can simply assign the Bitmap to the Image-Property of the PictureBox.

Is this specific enough?

EDIT:

You can convert your doubles with the range of 0.0000 to 0.5000 by the simply dividing by five and multiplying with 255 for each component. e.g.

bmpBitmap.SetPixel(iX, iY, 
Color.FromArgb((int)(arArray[iX, iY, 0] / 5 * 255), 
(int)(arArray[iX, iY, 1] / 5 * 255), 
(int)(arArray[iX, iY, 2] / 5 * 255)
);

You will probably have to adjust the array indices.

Emiswelt
If you need better performance than `SetPixel`, try using [`LockBits`](http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx).
Mark
A: 

hi, thanks for the reply. can you also tell me how do i transform this double values to unsigned integer between 0-255. i am looking for a similar logic as present in MATLAB (im2uint8).

ateendra
You should comment on my answer rather then posting an answer yourself. Or I won't get any message you commented.
Emiswelt
@Emiswelt - The OP has managed to create two separate accounts which is why they've answered rather than commenting.
ChrisF