Simple Image Processing in C#

Image processing is an important part of the Entertainment industry. This is the field where there is large possiblity of explorations if we get into its depth.Sometimes we do think about complexity of writing code to process an image … Matlab is an awesome tool provided to mankind for image editing but wen it comes to application development i think C# has got gr8 features .. Acc to me C# is a youngest sister of C++/Java.I am sure you won’t look back to any other language if you start working in C# once .. Soon I’ll post a article depicting various difference between C# and other languages.
Now coming to image processing part .It’s so simple in C#

void Image_Processing()
BitmapData BD=Bmap.LockBits(new Rectangle(0,0,Bmap.Width,Bmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); //Bmap is an Bitmap object of System.Drawing
int stride = BD.Stride; //Stride refers to the line by line scanning of image
System.IntPtr Scan0 = BD.Scan0; //Scan0 refers to the address of first bit of the stride(line)
byte * p = (byte *)(void *)Scan0;
int nOffset = stride – Bmap.Width*3; //Generally stride is more than usual RGB line
int nWidth = Bmap.Width * 3; //mul by 3 coz image is in RGB mode
for(int y=0;y<Bmap.Height;++y)
for(int x=0;x < nWidth; ++x )
/*This space can be used for various simple image processing functions*/
p[0] = (byte)(255-p[0]); //Inverting an image
p += nOffset;


Using System.Drawing objects in .net we can similarly process images in other .Net languages also.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: