How can we get the info from an image if it contains by calculating the no of pixels and there arrangement.

- 12,591
- 4
- 59
- 90
-
1Very low effort. This is not an expert question. Try google first and try yourself. – vidstige Apr 16 '12 at 13:47
-
this reminds me of a particular Queen song... – Scott M. Apr 16 '12 at 13:47
-
Just go to pixel level and edit it. :P Jokes apart [What have you tried till now ?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – Marshal Apr 16 '12 at 13:48
-
Please search a bit. [MSDN Bitmap.LockBits](http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx) – user703016 Apr 16 '12 at 13:49
3 Answers
You can make use of the Bitmap class in .Net
Here a nice example: Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters
Also the following StackOverflow (Question: How to manipulate images at pixel level in C#) provides already an answer :D
You can use the Bitmap (System.Drawing) class. Then, to manipulate pixels, use the methods GetPixel() and SetPixel(). But if you want a faster access to the pixels, read this article: Using the LockBits method to access image data by Bob Powell that exploits pointers, compiling with unsafe code.

- 24,203
- 9
- 60
- 84

- 16,329
- 10
- 48
- 66
Here's an example of manipulating pixel data using pointers.
unsafe
{
int red, blue, green;
editImage = new Bitmap("image.jpg");
editWidth = editImage.Width;
editHeight = editImage.Height;
data = editImage.LockBits(new Rectangle(0, 0, editWidth, editHeight),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
byte* dataPtr = (byte*)data.Scan0;
h = trackBar1.Value / 60.0;
D = 1 - Math.Abs((h % 2) - 1);
if (h >= 0 && h < 1)
{
for (int i = 0; i < editHeight; i++)
{
offsetStride = i * data.Stride;
for (int j = 0; j < editWidth; j++)
{
blue = dataPtr[(j * 3) + offsetStride];
green = dataPtr[(j * 3) + offsetStride + 1];
red = dataPtr[(j * 3) + offsetStride + 2];
if (green > blue) max = green;
else max = blue;
if (red > max) max = red;
if (green < blue) min = green;
else min = blue;
if (red < min) min = red;
s = (max == 0) ? 0 : 1d - (1d * min / max);
v = max / 255d;
C = v * s;
X = C * D;
E = v - C;
dataPtr[(j * 3) + offsetStride] = (byte)(min);
dataPtr[(j * 3) + offsetStride + 1] = (byte)((X + E) * 255);
dataPtr[(j * 3) + offsetStride + 2] = (byte)(max);
}
}
}
}
This just changes the hue of an image. For any reasonably large image > 100x100 pixels, don't bother using GetPixel or SetPixel unless performance doesn't matter.

- 5,680
- 10
- 49
- 74