0


I work with a camera that has its own API. The camera sends me an array of gray-scale image and I turn it to colorful.
However, when I do that, I get a picture that has black lines in it.
The image is this:

enter image description here


As you can see, the image has black lines in it and I don't understand why because the picture I get straight from the camera is alright and doesn't have black lines.

The code I use for getting the image is:

Camera.Memory.Lock(s32MemID);
Camera.Memory.ToIntPtr(s32MemID, out ptrImage);
short[] temp = new short[m_tMatrixArray.Length];
Marshal.Copy(ptrImage, temp, 0, temp.Length);
System.Buffer.BlockCopy(temp, 0, m_tMatrixArray, 0, temp.Length * sizeof(short));


The code I use for making the bitmap is:
colorArray is fine.

int[] data = new int[m_tMatrixArray.Length];
Color[] colorArray=new Color[256];
Color[] m_color = new Color[4096];
float l_dPaletteStepStep = (colorArray.Length - 1) / (float)m_color.Length;
getColorArray(colorArray);
for (int i = 0; i < m_color.Length; i++) m_color[i] = colorArray[(int)Math.Ceiling(i * l_dPaletteStepStep)];

for (int i = 0; i < m_tMatrixArray.Length; i++) data[i] = m_color[(int)m_tMatrixArray[i]].ToArgb(); 
Marshal.Copy(data,0,bmpData.Scan0,data.Length);
bmp.UnlockBits(bmpData);
Camera.Memory.Unlock(s32MemID);

videoImageControl.Image = bmp;
videoImageControl.Invalidate();



Thank you for your help.

TaW
  • 53,122
  • 8
  • 69
  • 111
  • Did you use the right stride when processing the data? Do you know the dimension of the original image? – TaW Dec 29 '16 at 10:41
  • Um... What do you mean? – kidneyThief Dec 29 '16 at 10:42
  • Bitmaps add a buffer to each scan line to fill it up to a multiple of 4. [See here](https://msdn.microsoft.com/en-us/library/system.drawing.imaging.bitmapdata.stride%28v=vs.110%29.aspx) – TaW Dec 29 '16 at 10:45
  • So what can I do about it? – kidneyThief Dec 29 '16 at 10:49
  • You need to calculate the stride and add it to the buffer.. There a couple of posts about that around. Search for 'Bitmap Stride' ! – TaW Dec 29 '16 at 10:50
  • How do I add it to the buffer? – kidneyThief Dec 29 '16 at 11:07
  • [Here](http://stackoverflow.com/questions/39046294/slanted-bitmap-stride-calculation-for-rgb565-c-sharp/39053336#39053336) I explain how to calculate the adresses. The acutal Image buffer already will have room for the padding therefore the target adress must include the actual scan line length. The source doesn't have it. What are the dimensions and the pixel depth of the images? - [Here](http://stackoverflow.com/questions/28310592/viewing-a-large-bitmap-image-using-memory-mapped-view/28314519#28314519) is more on calculating stride.. – TaW Dec 29 '16 at 11:32

0 Answers0