Howdy all,

My question is to do with programming, specifically LockBits on the .NET framework.

I'm working with a single dimensional array, representing a picture. The array is structured, so the first 3 elements have the r g and b values of the first pixel, the 4th, 5th and 6th elements have the r g and b values of the second pixel, and so on. The pixels are stored by rows (not columns).

I'm trying to write a "SetPixel" function using this. What I have so far is this:
PHP Code:
private void SetPixel(int xint ybyte rbyte gbyte bref byte[] rgbValuesint Width)
{
    
int px = (((Width) * 3) + (3));
    
rgbValues[px] = b;
    
rgbValues[px++] = g;
    
rgbValues[px++] = r;

This however, doesn't seem to work. It works in the sense that no error occur, but if I use this:
PHP Code:
SetPixel(320y000ref rgbValuesWidth);
SetPixel(321y000ref rgbValuesWidth);
SetPixel(322y000ref rgbValuesWidth);
SetPixel(323y000ref rgbValuesWidth);
SetPixel(324y000ref rgbValuesWidth);
SetPixel(325y000ref rgbValuesWidth);
SetPixel(326y000ref rgbValuesWidth);
SetPixel(327y000ref rgbValuesWidth);
SetPixel(328y000ref rgbValuesWidth);
SetPixel(329y000ref rgbValuesWidth); 
... there are gaps between the plotted pixels, both horizontally and vertically.



My question to you is:

How would I correctly calculate where to place the pixels in the setpixel function? Nothing I seem to try works and its starting to make my head explode (slowly ). If anyone has an answer I would be very appreciative.

Thanks in advance,

chem