This application explains basic concepts of image processing including brightening, converting to gray and adding notes to an image using System.Drawing.Imaging namespace classes.
Following code shows how to display an image in a picture box.
private
System.Windows.Forms.PictureBox p1;string path = abc.jpg;
p1.Image = new Bitmap(path);
This code show how to take the bitmap data:
Bitmap b =
new Bitmap(path);BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

The screen shot above shows an image before and after increasing brightness.
This is the main function, where we do the main processing. If you look into the code you will notice, I am using unsafe code, where I am doing the main processing. This is really important because unsafe mode allow it to run that piece of code without CLR, which make the code to run much faster. Here its important because we care about the speed of the routine.
public
static bool Brighten(Bitmap b, int nBrightness){
// GDI+ return format is BGR, NOT RGB.
BitmapData bmData
= b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
int nVal;
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - b.Width*3;
int nWidth = b.Width * 3;
for(int y=0;y<b.Height;++y)
{
for (int x = 0; x < nWidth; ++x)
{
nVal = (int) (p[0] + nBrightness);
if (nVal < 0) nVal = 0;
if (nVal > 255) nVal = 255;
p[0] = (byte)nVal;
++p;
}
p += nOffset;
}
}
b.UnlockBits(bmData);
return true;
} When you click on the Bright button this piece of code execute.
private
void btnBright_Click(object sender, System.EventArgs e){
try
{
string path = Path.Combine(tv1.SelectedNode.FullPath, lstFiles.SelectedItem.ToString());
Bitmap b = new Bitmap(path);
Brighten(b, m_nTrack);
p2.Image = b;
}
catch{}
} This next screen-shot shows the gray effect.


Ehi BayePosted Feb 7, 2018, 5:49 AM EST
Does this work in .net core ? I get errors for the following keywords: (unsafe, v1. lstFiles m_nTrack and p2.Image
Kuppurasu NagarajTOP 100Posted Apr 24, 2016, 8:51 AM EDT
Nice Sharing..
kushal malshettyPosted Sep 21, 2015, 1:21 AM EDT
hey as this is my first project , im having difficulty in preparing documentation for this project . so if anyone has already prepared then plz mail me on [email protected]
Muhammad AmerPosted Feb 19, 2013, 7:01 AM EST
I need code for image mirroring and Applying Blur effect. Could You please help
Sumit SharmaeditedPosted Apr 3, 2012, 10:33 PM EDTEdited Apr 3, 2012, 11:10 PM EDT
Hi, This is nice article.i am using this code.image display properly. But getting error 'parameter is not valid' if i do any operation on any image. I got the solution........ in function i change the pixelformat. Now i use the bitmap object pixelformat BitmapData bmData = b.LockBits(r,ImageLockMode.ReadWrite, b.PixelFormat); and its work but......but..... now i get another problem.its show 'Attempted to read or write protected memory.this is often an indication that other memory is correpted.' What is it mean?? can any one help me to short out this.??
Raman ShresthaPosted Jun 12, 2011, 9:58 PM EDT
i try to use ur software but i cannot open file in it.. i select folder but it doesnt show jpg or other file but only show ini file. can u help me.
JIE CHENPosted Dec 1, 2010, 11:15 PM EST
THX. IT'S REALLY HELPFUL
Ahlam AlqutamiPosted Nov 3, 2010, 4:32 AM EDT
please I need code for laplacin filter in C#
zhang lizhongPosted Nov 1, 2010, 5:16 AM EDT
just look it!!
Gourav Kumar SoniPosted Sep 8, 2010, 6:17 AM EDT
nice
bach xuanPosted Sep 6, 2010, 7:11 PM EDT
I like Image Processing. I am happy when I have this article. Thank you.
Jaypee BacolPosted Dec 7, 2009, 5:17 PM EST
How to feather or smooth the edges of the subject. For example, a chicken in a picture. I want to feather or smooth the edges of the chicken with transparent background or using ARGB elements. Please help me this is an urgent. Jaypee
Guendolyn BarrientosPosted Aug 9, 2009, 5:53 PM EDT
Good day to you sir... I would like to ask for your help.. I am having my thesis subject now and I have no enough knowledge about c#... My groupmates surrender... Our project is about our periofical index of our library... Exactly with image processing of the manually used periodical index... Pls help me the codes... Thamks... Looking forward for your response... Thanks...
vin kumPosted Mar 5, 2009, 5:46 AM EST
hey its very useful
adam seklanieditedPosted Dec 5, 2008, 4:44 AM ESTEdited Mar 27, 2009, 9:41 AM EDT
ssssss
Kunal PawarPosted Nov 19, 2008, 8:21 PM EST
Hi, can u tell how to open Tiff file (500 MB) in Picture box
Bojan DukaricPosted Oct 31, 2008, 4:04 AM EDT
Hi! How could I determine the speed of moving object of a video, taken in real time. I have one programe which makes from this video pictures in sequence. I would like to determine the speed of an object(somekind of mixer), based on this picture sequence with image processing in C#. Can enybodey please help me to resolve this problem? Thank you...!
Sobia ZeeshanPosted Jan 2, 2008, 4:39 PM EST
Assalam O Alaikum, I am a BCS student and have to choose one language to develop E-Photographer. Either I should choose c#.net or vb.net? Kindly guide me. I have learnt c++ and Java during my BCS courses. Regards,
hamid hoseiniPosted Nov 26, 2007, 1:04 AM EST
how can i get size of images?
samir BPosted Feb 17, 2007, 11:31 PM EST
hey guys..... i wana do a proj of Image Warping in C#...... can u guys help me out by tellin me some API or related info abt it ???
sou souPosted Feb 15, 2007, 10:14 AM EST
I's a good web site.Please I need your help to find some code source in c# detecting contour of image..thank you.