Click here to Skip to main content
13,002,000 members (78,401 online)
Rate this:
Please Sign up or sign in to vote.
See more:
How to read a 8-bit grayscale JPEG image using C#?
i need this code
Posted 26-Apr-11 11:51am
SAKryukov 26-Apr-11 18:22pm
Tag the question properly and clarify! See my answer explaining why you need to clarify.
Sandeep Mewara 27-Apr-11 0:49am
No effort.

"I need this code" => and we work for you, right? :doh:
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Just use Image.FromFile.
SAKryukov 26-Apr-11 18:21pm
Nishant, this is quite good but... You cannot be sure you're answering right question. I counted 6 variants.
Please see my answer.
Nishant Sivakumar 26-Apr-11 18:23pm
I went with the most common choice (WinForms). But yes, it's a guess on my part :-)
SAKryukov 26-Apr-11 19:55pm
Should OP choose to clarify it, we will be able to right a real thing for sure :-)
Dave Kreskowiak 27-Apr-11 13:48pm
From the OP:

I want to read only grey pixel (8-bit)
and maybe you understand from this code :

Bitmap img1 = new Bitmap(fname1);
pictureBox1.Image = img1;
int[] myarray;
myarray = new int[256];

for (int i = 0; i< img1.Width; i++)
for (int j = 0; j< img1.Height; j++)
Color PixelColor = img1.GetPixel(i, j); (1)
int gray = (PixelColor.R + PixelColor.G + PixelColor.B) / 3; (2)

//gray = gray + 1;
myarray[gray] = myarray[gray] + 1;

in step one: i read the colored pixel by (getpixel)
in step two :i transfered the coloured pixel to grey pixel
i want to dispense on step two , and thet by getting method similarity the work of (getpixel)
but the pixel must be from the type of : bitmap and not from the type of color

and thanks for your help !
Dave Kreskowiak 27-Apr-11 13:49pm
First, do NOT use GetPixel. It's way too slow for this.

You can find an example ofa Grayscale Filter in C# at
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

It depends on what do you mean by "read". Do you need to access the bits in a bitmap and manipulate with this data or you just needs to draw it on screen. Also important in case you need bit data: do you need it read-only or read-write?

In both cases it also depends on what do you need to use, System.Drawing or WPF — the solutions will be quite different. Six variants, by my count. No, I'm not going to answer them all. Tag your question properly and ask exactly what do you want to do with data.

Member 11115090 16-Feb-15 3:15am
how can work with the value of grayscale image i know getpixel& setpixel is for it but have the graysacle image with set pixel have 3 argument (r,g,b)
Sergey Alexandrovich Kryukov 16-Feb-15 10:11am
Are you going to continue ignoring the questions? Please clarify what you are using, before we can discuss anything.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170624.1 | Last Updated 27 Apr 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100