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, 10:49 AM
Does this work in .net core ? I get errors for the following keywords: (unsafe, v1. lstFiles m_nTrack and p2.Image
Kuppurasu NagarajPosted Apr 24, 2016, 12:51 PM
Nice Sharing..
kushal malshettyPosted Sep 21, 2015, 5:21 AM
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, 12:01 PM
I need code for image mirroring and Applying Blur effect. Could You please help
Sumit SharmaeditedPosted Apr 4, 2012, 2:33 AMEdited Apr 4, 2012, 3:10 AM
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 13, 2011, 1:58 AM
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 2, 2010, 4:15 AM
THX. IT'S REALLY HELPFUL
Ahlam AlqutamiPosted Nov 3, 2010, 8:32 AM
please I need code for laplacin filter in C#
zhang lizhongPosted Nov 1, 2010, 9:16 AM
just look it!!
Gourav Kumar SoniPosted Sep 8, 2010, 10:17 AM
nice
bach xuanPosted Sep 6, 2010, 11:11 PM
I like Image Processing. I am happy when I have this article. Thank you.
Jaypee BacolPosted Dec 7, 2009, 10:17 PM
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, 9:53 PM
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, 10:46 AM
hey its very useful
adam seklanieditedPosted Dec 5, 2008, 9:44 AMEdited Mar 27, 2009, 1:41 PM
ssssss
Kunal PawarPosted Nov 20, 2008, 1:21 AM
Hi, can u tell how to open Tiff file (500 MB) in Picture box
Bojan DukaricPosted Oct 31, 2008, 8:04 AM
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, 9:39 PM
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, 6:04 AM
how can i get size of images?
samir BPosted Feb 18, 2007, 4:31 AM
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, 3:14 PM
I's a good web site.Please I need your help to find some code source in c# detecting contour of image..thank you.