|
-
Oct 18th, 2006, 01:27 AM
#1
Thread Starter
G&G Moderator
I thought this might belong here..
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 x, int y, byte r, byte g, byte b, ref byte[] rgbValues, int Width)
{
int px = (((y * Width) * 3) + (x * 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(320, y, 0, 0, 0, ref rgbValues, Width);
SetPixel(321, y, 0, 0, 0, ref rgbValues, Width);
SetPixel(322, y, 0, 0, 0, ref rgbValues, Width);
SetPixel(323, y, 0, 0, 0, ref rgbValues, Width);
SetPixel(324, y, 0, 0, 0, ref rgbValues, Width);
SetPixel(325, y, 0, 0, 0, ref rgbValues, Width);
SetPixel(326, y, 0, 0, 0, ref rgbValues, Width);
SetPixel(327, y, 0, 0, 0, ref rgbValues, Width);
SetPixel(328, y, 0, 0, 0, ref rgbValues, Width);
SetPixel(329, y, 0, 0, 0, ref rgbValues, Width);
... 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
Visual Studio 6, Visual Studio.NET 2005, MASM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|