Lockbits error [modified]
-
I have a 512x512 image, and using lockbits and unsafe code, i visit each pixel to retrieve that pixel value. This is a grayscale image. What i want to do is start the retrieval from the 256th pixel in each row (or, collectively, the right half of the image). Heres what i tried:
inputImg = Image.FromFile(inputImgPath);
b = (Bitmap)inputImg;
BitmapData bmData = b.LockBits(new Rectangle(256, 0, b.Width, b.Height),
ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte* p = (byte*)(void*)Scan0;
int nOffset = stride - 256;
for (int y = 0; y < b.Height; ++y)
{
for (int x = 0; x < 256; ++x)
{
current = (byte)p[0];
p++;
}
p += nOffset;
}
}
b.UnlockBits(bmData);The problem is occurs when i use the LockBits method. The compiler says the parameter is not valid.
modified on Saturday, August 23, 2008 12:33 AM
-
I have a 512x512 image, and using lockbits and unsafe code, i visit each pixel to retrieve that pixel value. This is a grayscale image. What i want to do is start the retrieval from the 256th pixel in each row (or, collectively, the right half of the image). Heres what i tried:
inputImg = Image.FromFile(inputImgPath);
b = (Bitmap)inputImg;
BitmapData bmData = b.LockBits(new Rectangle(256, 0, b.Width, b.Height),
ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte* p = (byte*)(void*)Scan0;
int nOffset = stride - 256;
for (int y = 0; y < b.Height; ++y)
{
for (int x = 0; x < 256; ++x)
{
current = (byte)p[0];
p++;
}
p += nOffset;
}
}
b.UnlockBits(bmData);The problem is occurs when i use the LockBits method. The compiler says the parameter is not valid.
modified on Saturday, August 23, 2008 12:33 AM
gigahertz205 wrote:
The compiler says the parameter is not valid.
What parameters is it supposed to take? Does it take the Rectangle object? ---modified Try using the
code block
button to make your code snippet easier to read."The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
-
gigahertz205 wrote:
The compiler says the parameter is not valid.
What parameters is it supposed to take? Does it take the Rectangle object? ---modified Try using the
code block
button to make your code snippet easier to read."The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
The parameters are as follows: public System.Drawing.Imaging.BitmapData LockBits(System.Drawing.Rectangle rect, System.Drawing.Imaging.ImageLockMode flags, System.Drawing.Imaging.PixelFormat format) And the rectangle: public Rectangle(int x, int y, int width, int height) This worked when my starting point was at (0,0) and visited every single pixel in the image, but when its at (256,0), it gives me back an error. EDIT: this is where i got the code from (http://www.codeproject.com/KB/GDI-plus/csharpgraphicfilters11.aspx[^])
-
The parameters are as follows: public System.Drawing.Imaging.BitmapData LockBits(System.Drawing.Rectangle rect, System.Drawing.Imaging.ImageLockMode flags, System.Drawing.Imaging.PixelFormat format) And the rectangle: public Rectangle(int x, int y, int width, int height) This worked when my starting point was at (0,0) and visited every single pixel in the image, but when its at (256,0), it gives me back an error. EDIT: this is where i got the code from (http://www.codeproject.com/KB/GDI-plus/csharpgraphicfilters11.aspx[^])
You might want to ask the author, Christian, in the said article's message board.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham